I need to use some variables defined in a script but when I call them their values are 0. I don't know what I am doing wrong.
Example:
Script1.cs
public int cont;
public void Method() { cont++; }
void Update() { Method(); }
Script2.cs
public Script1 usingScript1;
void MethodX()
{
usingScript1.GetComponent<Script1>();
Debug.Log(usingScript1.cont);
}
void Update() { MethodX(); }
This script should be showing the "cont" variable increasing since it's being called from Update(), but that's not happening. When I call it, it's 0 and don't increase.
Also, I refer the object which contains Script1.cs in the Ispector. It must be a simple thing that I'm missing. I even tried calling Method().
UpdatewhenRigidBodiesare involved? In that case I agree with you. Otherwise there is nothing wrong with overridingUpdateas you can see in my spiffy GPGPU n-Body galaxy simulation. :)