- Home /
Question by
AlienHook · Jan 16, 2014 at 10:15 PM ·
javascriptvariablesaccess
Trying to access a variable in a different script on a different game object.
I'm using JavaScript. I have a public variable called "playerLife" which is a float. It's in a script called "Battle" and placed on an object named "Cube". The error I'm getting is "An instance of type 'Battle' is required to access non static member 'playerLife'." How do I retrieve this variable in a separate script which is on a separate game object?
I've tried:
function Start() {
var yourLife: float = GameObject.Find("Cube").GetComponent(Battle.playerLife);
Debug.Log(yourLife);
}
Comment
You should have a look at these lessons: Learn Unity. (esp. beginner #20)
Your answer
Follow this Question
Related Questions
Access other variables please help :( 1 Answer
Help with variables 2 Answers
Accessing a js static var from a c# script 1 Answer