For instance, i have the player variable in my enemy script:
player = GameObject.Find("Player2");
I want to know, if the boolean flag 'running' is true or false in the player, but the in the enemy script. How do i do that?
Thank you
For instance, i have the player variable in my enemy script:
player = GameObject.Find("Player2");
I want to know, if the boolean flag 'running' is true or false in the player, but the in the enemy script. How do i do that?
Thank you
There are 2 ways.
Use a static variable in your player script . This means that every instance of the player script will share this variable instance. If Player1 and Player2 both have this script attached, there will only ever be one of this variable that they are both using.
playerScript.js
static var running : boolean = false;
anyOtherScript.js
if(playerScript.running)
//do something
Use a public variable and get it from the instance of the script.
playerScript.js
var running : boolean = false; //public by default. You could specify with keyword public.
anyOtherScript.js
var player : GameObject = GameObject.FindWithTag("Player2"); //more efficient than Find
var script : playerScript = player.GetComponent(playerScript); //get script instance
if(script.running)
//do something