I am currently trying to pass a variable between a script in unity, and all of the questions previously posted seem to not help, if anything have just confused this issue more than it was intended to be.
My issue is, I have a integer named count in my PlayerController Script, and the variable of count is needed in another script called BounceObject to be used within an if statement to compare against.
This is my Player controller script, with some parts of the code missing.
public int count;
void SetCountText()
{
countText.text = "Score: " + count.ToString ();
if (count >= 12)
{
winText.text = "You have won!";
}
}
This is the script that I am trying to access the variable of count in, named BounceObject
public PlayerController script;
void Start()
{
script = getComponent<PlayerController>();
}
void Update()
{
if (script.count >= 8)
{
#Do Stuff here...
}
}
I am not sure if I have made a mistake within my code or not. For reference the BounceObject Script is only found in a prefab which I then import into my game. The integer of count will also change so it is needed to be updated in the BounceObject script when it is changed in PlayerController.
Many thanks!
PlayerControllera component of the same game object to whichBounceObjectis attached?