Hi, I’m totally green in Unity. On a tutorial I was watching I found this script
#pragmastrict
var cSpeed:float = 10.0;
var sFactor:float = 10.0;
//Add 1 to score
staticvar playerScore:int = 0;
staticvar enemyScore:int = 0;
function Start ()
{
rigidbody.addForce (10,0,0);
}
function Update () {
}
After adding this to object I tried to run the build but it keeps giving bug output like this (Picture 1)
Can someone tell me how to make this script work?
PS.:Tutorial is dated on 23.03.2012.
You need to use GetComponent; the shortcut accessors were removed quite some time ago, so that must be from an old tutorial. (Plus you made a typo; there’s no function called “addForce” in any case.) Also, use code tags when posting code.
#pragmastrict
//Assign your rigidbody in the inspector or use GetComponent
var rb: Rigidbody;
var cSpeed : float = 10.0;
var sFactor : float = 10.0;
//Add 1 to score
staticvar playerScore : int = 0;
staticvar enemyScore : int = 0;
function Start ()
{
rb.AddForce (10,0,0);
}
function Update () {
}
Tidied it a little, they changed it ages ago so you need your own reference to the Rigidbody component.
Assign it within the inspector or use GetComponent.
You then use your own reference to use AddForce (Capital ‘A’, methods generally start with a capital, unlike variables.)