This question was
closed Dec 01, 2015 at 09:28 PM by
Immortus12 for the following reason:
Change it to static variable seems to be good.
Question by
Immortus12 · Nov 22, 2015 at 12:40 AM ·
variablepublic variablescritpingchange variable
Can't change value of my variable from another script.
Hi, I'm trying to change value of my variable "firstTeamID" to for example 2, from another script. This is code from class with that variable:
public class Simulation : MonoBehaviour
{
public int firstTeamID;
void Start()
{
// Some code
}
void StartSimulation()
{
//Simulation
}
}
When i try to change it outside the script, value remains 0 (default value). In the beggining when i test my Simulation class i set value from Start method and it works fine. But now i have to set it from another script... I must also say that Simulation script is off at the beginning. I turn it on when i set value of "firstTeamID". I 'm changing value from another script by that code:
public class Menu : MonoBehaviour
{
public Simulation simulationScript;
//Some code
public void NextMatch()
{
simulationScript.firstTeamID = 2;
}
}
When variable is public i can change its value i nInspector before play mode but it also hcange nothing.
Comment