Not moving,please help
This is my first code,i didnt program in unity before:
public class miscare : MonoBehaviour {
float speed = 10.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void UpdateFixed () {
Rigidbody2D myRigidbody = GetComponent<Rigidbody2D>();
if (Input.GetButton("Horizontal"))
myRigidbody.AddForce(Vector2.right * speed);
}
}
The square isnt moving,no errors. Please help
poza.png
(172.8 kB)
Comment
Answer by jgodfrey · Mar 29, 2016 at 11:50 PM
The obvious issue is that "UpdateFixed" method should be "FixedUpdate". Beyond that, you probably don't want to call GetComponent in FixedUpdate. Though it'll work, it's very inefficient. You should make that call in Start (or Awake) and use the cached reference in FixedUpdate.
Your answer
Follow this Question
Related Questions
Make the Player unable to move to opposite direction 1 Answer
Raycast is hitting enemy even when not in contact with it? 2 Answers
Character Rotation 0 Answers
moving an object on the y and x axis to mouse location 0 Answers
Unity2D How to dodge roll? 0 Answers