Home > other >  Unity static variable problem, a beginner
Unity static variable problem, a beginner

Time:09-18

I wrote a script (Timer), only a public static float are stored in the variable, for time,
And then another to use the script in the static variable (PointItemIcon) hung on in a lot of game objects, and then I go to modify the static variables, didn't have to share effect, after modify the static variables, other objects script Timer. The time value did not change
Please answer thank you!



Public class PointItemIcon: MonoBehaviour, IPointerEnterHandler
{

Public int key;//backpack items keys

Bool timeBool;//control timer switch
BagManager managerObj;//BagManager instance of the



Void the Update ()
{
If (timeBool)
{

The Timer. The time +=time. DeltaTime;

If (Timer. The time & gt; 2)
{

ManagerObj. BagTip. SetActive (false);

TimeBool=false;


}

}

}
Public void OnPointerEnter (PointerEventData eventData)
{

If (gameObject. ActiveSelf==true)
{
ManagerObj=BagManager. Instance;
ManagerObj. BagTip. SetActive (true);
ManagerObj. BagTip. Transform. GetChild (0). GetComponent (a). The text="& lt; Color=red> Name: "+ managerObj dic [key] the Name +" & lt;/color> \ n Dic BuyPrice: "+ managerObj. [key]. BuyPrice +" & lt;/color> \ n Dic SellPrice: "+ managerObj. [key] SellPrice +" & lt;/color> ";
The Timer. The time=0;
TimeBool=true;



}
}



}

CodePudding user response:

Script similar properties, on the object of the game, why change have this sharing effect, illogical, you can try the script of the value of time is to obtain a value of the parent, and modifying the superclass object of the game value

CodePudding user response:

The Timer. The time will surely become it is the only global static variables, the Timer. The time +=time. DeltaTime; Are you sure this call and the Timer class without error
  • Related