I am trying to make a ball move but even though my code is right an error is being displayd
The code I am using is
#pragma strict
var rotationSpeed = 100;
function Update () {
var rotation : float = Input.GetAxis ("Horizontal") * rotationSpeed;
rotation *= Time.deltaTime;
rigidbody.AddRelativeTorqe (Vector3.back * rotation);
}
I don’t know why it is coming but the error is-
“Assets/BallControl.js(8,1): BCE0144: ‘UnityEngine.Component.rigidbody’ is obsolete. Property rigidbody has been deprecated. Use GetComponent() instead. (UnityUpgradable)”
and-
"Assets/BallControl.js(8,11): BCE0019: ‘AddRelativeTorqe’ is not a member of ‘UnityEngine.Component’.
"
As it says, ‘rigidbody’ call was removed from Unity. It used to be used as a quick access to an object’s Rigidbody component. However, it was just a shortcut and ran a GetComponent() call in the background. They removed it because GetComponent() is slow and should not be used repeatedly. The best way to use it is storing the reference in Awake()/Start() and using the saved variable.
Also, typo in ‘AddRelativeTorqe’, should be ‘AddRelativeTorque’.
#pragma strict
var rotationSpeed = 100;
var myRigidbody : Rigidbody;
function Start ()
{
myRigidbody = GetComponent.<Rigidbody>(); //Store a reference to this object's Rigidbody
}
function Update ()
{
var rotation : float = Input.GetAxis ("Horizontal") * rotationSpeed;
rotation *= Time.deltaTime;
myRigidbody.AddRelativeTorque (Vector3.back * rotation);
}