-1
My code is not working, causing the following error:
Nullreferenceexception
The point is to jump, but I can only walk:
public class player : MonoBehaviour
{
public float Speed;
private Rigidbody2D rig;
public float JumpForce;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
Move();
Jump();
}
void Move()
{
Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0f, 0f);
transform.position += movement * Time.deltaTime * Speed;
}
void Jump()
{
if(Input.GetButtonDown("Jump"))
{
rig.AddForce(new Vector2(0f, JumpForce), ForceMode2D.Impulse);
}
}
}
Hello Erick, welcome to [en.so]. I suggest you edit your question and add the criteria, from [Re], it is worth a lot to take a look, so you can elaborate a good question!
– gleisin-dev