new Vector3(h, 0, )
kısmında virgülden sonra da bir şey girilmesi gerekiyor. 0 girebilirsiniz hatanın gitmesi için. Şöyle çalışır yani new Vector3(h, 0, 0)
ama istediğiniz mi olur bilmiyorum oraya ne gelecek yapmak istediğinize siz karar vermelisiniz .using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public Transform aimTarget;
float speed = 3f;
bool hitting;
void Update()
{
float h = Input.GetAxisRaw("Horizontal");
float v = Input.GetAxisRaw("Vertical");
if (Input.GetKeyDown(KeyCode.F)) ;
{
hitting = true;
}
if (Input.GetKeyUp(KeyCode.F)) ;
{
hitting = false;
}
if (hitting)
{
aimTarget.Translate(new Vector3(h, 0, 0) * speed * Time.deltaTime);
{
if (h != 0 || v != 0)
{
transform.Translate(new Vector3(h, 0, v) * speed * Time.deltaTime);
}
}
}
}
}
Tamam şimdi anladım sağ ol.Düzeltilmiş hali. İki süslü parantez atlamışsın.Kod:using System.Collections; using System.Collections.Generic; using UnityEngine; public class Player : MonoBehaviour. { public Transform aimTarget; float speed = 3f; bool hitting; void Update() { float h = Input.GetAxisRaw("Horizontal"); float v = Input.GetAxisRaw("Vertical"); if (Input.GetKeyDown(KeyCode.F)) ; { hitting = true; } if (Input.GetKeyUp(KeyCode.F)) ; { hitting = false; } if (hitting) { aimTarget.Translate(new Vector3(h, 0, 0) * speed * Time.deltaTime); { if (h != 0 || v != 0) { transform.Translate(new Vector3(h, 0, v) * speed * Time.deltaTime); } } } } }
Düzeltilmiş hali. İki süslü parantez atlamışsın.Kod:using System.Collections; using System.Collections.Generic; using UnityEngine; public class Player : MonoBehaviour. { public Transform aimTarget; float speed = 3f; bool hitting; void Update() { float h = Input.GetAxisRaw("Horizontal"); float v = Input.GetAxisRaw("Vertical"); if (Input.GetKeyDown(KeyCode.F)) ; { hitting = true; } if (Input.GetKeyUp(KeyCode.F)) ; { hitting = false; } if (hitting) { aimTarget.Translate(new Vector3(h, 0, 0) * speed * Time.deltaTime); { if (h != 0 || v != 0) { transform.Translate(new Vector3(h, 0, v) * speed * Time.deltaTime); } } } } }
Düzeltilmiş hali. İki süslü parantez atlamışsın.Kod:using System.Collections; using System.Collections.Generic; using UnityEngine; public class Player : MonoBehaviour. { public Transform aimTarget; float speed = 3f; bool hitting; void Update() { float h = Input.GetAxisRaw("Horizontal"); float v = Input.GetAxisRaw("Vertical"); if (Input.GetKeyDown(KeyCode.F)) ; { hitting = true; } if (Input.GetKeyUp(KeyCode.F)) ; { hitting = false; } if (hitting) { aimTarget.Translate(new Vector3(h, 0, 0) * speed * Time.deltaTime); { if (h != 0 || v != 0) { transform.Translate(new Vector3(h, 0, v) * speed * Time.deltaTime); } } } } }
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public Transform aimTarget;
float speed = 3f;
bool hitting;
void Update()
{
float h = Input.GetAxisRaw("Horizontal");
float v = Input.GetAxisRaw("Vertical");
if(Input.GetKeyDown(KeyCode.F));
{
hitting = true;
}else if(Input.GetKeyUp(KeyCode.F));
{
hitting = false;
}
if ( hitting)
{
aimTarget.Translate (new Vector3(h ,0 , 0 ) * speed * Time.deltaTime);
{
if ( h != 0 || v != 0)
{
transform.Translate(new Vector3(h , 0 , v ) * speed * Time.deltaTime );
}
}
}
}
}
Kod:using System.Collections; using System.Collections.Generic; using UnityEngine; public class Player : MonoBehaviour. { public Transform aimTarget; float speed = 3f; bool hitting; void Update() { float h = Input.GetAxisRaw("Horizontal"); float v = Input.GetAxisRaw("Vertical"); if(Input.GetKeyDown(KeyCode.F)); { hitting = true; }else if(Input.GetKeyUp(KeyCode.F)); { hitting = false; } if ( hitting) { aimTarget.Translate (new Vector3(h ,0 , 0 ) * speed * Time.deltaTime); { if ( h != 0 || v != 0) { transform.Translate(new Vector3(h , 0 , v ) * speed * Time.deltaTime ); } } } } }
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public Transform aimTarget;
float speed = 3f;
bool hitting;
void Update()
{
float h = Input.GetAxisRaw("Horizontal");
float v = Input.GetAxisRaw("Vertical");
if (Input.GetKeyDown(KeyCode.F))
{
hitting = true;
}
else if (Input.GetKeyUp(KeyCode.F))
{
hitting = false;
}
if (hitting)
{
aimTarget.Translate(new Vector3(h, 0, 0) * speed * Time.deltaTime);
{
if (h != 0 || v != 0)
{
transform.Translate(new Vector3(h, 0, v) * speed * Time.deltaTime);
}
}
}
}
}
If ve else ifadesinin sonuna tanımlarken noktalı virgül konulmaz.Kod:using System.Collections; using System.Collections.Generic; using UnityEngine; public class Player : MonoBehaviour. { public Transform aimTarget; float speed = 3f; bool hitting; void Update() { float h = Input.GetAxisRaw("Horizontal"); float v = Input.GetAxisRaw("Vertical"); if (Input.GetKeyDown(KeyCode.F)) { hitting = true; } else if (Input.GetKeyUp(KeyCode.F)) { hitting = false; } if (hitting) { aimTarget.Translate(new Vector3(h, 0, 0) * speed * Time.deltaTime); { if (h != 0 || v != 0) { transform.Translate(new Vector3(h, 0, v) * speed * Time.deltaTime); } } } } }
If ve else ifadesinin sonuna tanımlarken noktalı virgül konulmaz.Kod:using System.Collections; using System.Collections.Generic; using UnityEngine; public class Player : MonoBehaviour. { public Transform aimTarget; float speed = 3f; bool hitting; void Update() { float h = Input.GetAxisRaw("Horizontal"); float v = Input.GetAxisRaw("Vertical"); if (Input.GetKeyDown(KeyCode.F)) { hitting = true; } else if (Input.GetKeyUp(KeyCode.F)) { hitting = false; } if (hitting) { aimTarget.Translate(new Vector3(h, 0, 0) * speed * Time.deltaTime); { if (h != 0 || v != 0) { transform.Translate(new Vector3(h, 0, v) * speed * Time.deltaTime); } } } } }
Evet ama noktali virgülü silsemde hataların hiçbiri gitmiyor.
Hatalar gitti düzeldi fakat karakteri hala hareket etiremiyorum sizce nedeni ne olabilir?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public float hareketHizi=1f;
void Update()
{
float h = Input.GetAxisRaw("Horizontal");
float v = Input.GetAxisRaw("Vertical");
gameObject.transform.position = new Vector2(transform.position.x + (h * hareketHizi),transform.position.y + (v * hareketHizi));
}
}
İzlediğiniz Video'yu atmadan bilemem birçok yerde hata yapmış olma olasılığınız var. Ne tarz oyun yaptığınızıda bilmiyorum. Videonun bazı kısımlarını atlamışsınızdır belki ya da yanlış yapmışsınızdır.
En basit olarak bunu deneyebilirsiniz.
Kod:using System.Collections; using System.Collections.Generic; using UnityEngine; public class Player : MonoBehaviour. { public float speed=1f; void Update() { float h = Input.GetAxisRaw("Horizontal"); float v = Input.GetAxisRaw("Vertical"); gameObject.transform.position = new Vector2(transform.position.x + (h * speed),transform.position.y + (v * speed)); } }
Player scriptini başka bir objeye atadıysanız kaldırıp sadece Player objesine atayın.
Bu sitenin çalışmasını sağlamak için gerekli çerezleri ve deneyiminizi iyileştirmek için isteğe bağlı çerezleri kullanıyoruz.