public class CatMovement : MonoBehaviour
{
public bool OnGround = true;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
Rigidbody2D body = GetComponent<Rigidbody2D>();
if (Input.GetKey(KeyCode.UpArrow) && OnGround)
{
// Getting the rigidbody component of the sprite - vector 3 since using 3 values (x,y,z)
// GetComponent<Rigidbody2D>().velocity = new Vector3(0, 10, 0);
body.AddRelativeForce(new Vector2(0, 1000));
this.OnGround = false;
}
if (Input.GetKey(KeyCode.RightArrow))
{
body.AddRelativeForce(new Vector2(50, 0));
}
if (Input.GetKey(KeyCode.LeftArrow))
{
body.AddRelativeForce(new Vector2(-50, 0));
}
}
}
public class CatMovement : MonoBehaviour
{
public bool OnGround = true;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
Rigidbody2D body = GetComponent<Rigidbody2D>();
if (Input.GetKey(KeyCode.UpArrow) && OnGround)
{
// Getting the rigidbody component of the sprite - vector 3 since using 3 values (x,y,z)
// GetComponent<Rigidbody2D>().velocity = new Vector3(0, 10, 0);
body.AddRelativeForce(new Vector2(0, 1000));
this.OnGround = false;
}
if (Input.GetKey(KeyCode.RightArrow))
{
body.AddRelativeForce(new Vector2(50, 0));
}
if (Input.GetKey(KeyCode.LeftArrow))
{
body.AddRelativeForce(new Vector2(-50, 0));
}
}
}