My code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Cube : MonoBehaviour {
private Rigidbody rigidbody;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if (Input.GetKey (KeyCode.UpArrow))
{
rigidbody.AddForce (Vector2.up * 2000);
}
}
}
Problem in 7th line (private Rigidbody rigidbody;):
“no value will ever be assigned to the “Cube.Rigidbody” field and the default value of this field will always be used: null.”
I dont know what should I do, cube does not move when I pressing up arrow, can someone help me?