I am getting the following error…
Assets/Standard Assets/Scripts/Lander.js(13,32): BCE0020: An instance of type ‘UnityEngine.Component’ is required to access non static member ‘rigidbody’.
This error occures when trying to create a static variable,
static var landerVSI = (rigidbody.velocity.y);
Any hints would be appreciated.
that will not work.
statics are not object bound but class bound and as a class it has no GetComponent(rigidbody).xx (which is what rigidbody.xx stands for), as that only exists for monobehaviours attached to a gameobject
what you are looking for is setting that variable in the start function
Thanks for the reply dreamora,
What I want to do is access a variable contaning the velocity of a gameobject (in the Y and z planes), and then display and update that information using guiText.txt to the game screen.
I will need a static variable in order to pass the information to a different script, right?
The command
Debug.Log(rigidbody.velocity.y);
does display the information I need, so how do I pass that information to another script that will be handling guiText display?? are you saying that I just move that variable declaration to the start function and I am good to go??
thanks again for your assistance…
Actually in JS you don’t have to put it in Start. But you do have to declare it as a float first and then assign rigidbody.velocity.y the next line.
If the purpose is just to access from another script, then it’s unlikely that you want it to be static, so use the usual GetComponent methods of doing that (see the docs about accessing other game objects if you don’t already know).
–Eric
Ahh ok, would this work then? (cant test coz I am still at work)…
static var landerVS : float;
static var landerHS : float;
function Update() {
landerHS = (rigidbody.velocity.y);
landerVS = (rigidbody.velocity.z);
}
thanks.
Edit, this works a treat, thanks for the help guys.
I installed unity on work PC… lol, addicting isnt it?