Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

Trying to access a variable in a different script on a different game object.

$
0
0
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); }

Viewing all articles
Browse latest Browse all 171066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>