17-05-2019, Saat: 01:42
Öncelikle kodlama vs. hiç bir bilgim yok sağdan soldan öğrenerek yapmaya çalışıyorum fakat ''Statik olmayan alanı yöntemi veya özelliği için nesne başvurusu gerekiyor'' hatasında takıldım (GetComponent) çözemiyorum yardımcı olabilir misiniz?
Kodlama aşağıdaki gibi.
private Rigidbody2D rb2d;
private Animator anim;
public float hiz = 30f;
public float ziplamaGucu = 200f;
// Start is called before the first frame update
void Start() {
rb2d = GameObject.GetComponent<Rigidbody2D>();
anim = GameObject.GetComponent<Animator>();
}
// Update is called once per frame
void Update() {
}
private void FixedUpdate()
{
float h = Input.GetAxis("Horizontal");
rb2d.AddForce(Vector2.right * hiz * h);
}
}
private Animator anim;
public float hiz = 30f;
public float ziplamaGucu = 200f;
// Start is called before the first frame update
void Start() {
rb2d = GameObject.GetComponent<Rigidbody2D>();
anim = GameObject.GetComponent<Animator>();
}
// Update is called once per frame
void Update() {
}
private void FixedUpdate()
{
float h = Input.GetAxis("Horizontal");
rb2d.AddForce(Vector2.right * hiz * h);
}
}