[solved] A variable is being set by a variable from a different instance of the script when it should not be.
So I have this script attached to two different game objects. In the inspector I have set the localDecay to two different numbers. My intention is that when the setDecay function is called for one of the objects that the unique localDecay value for that objects will be used to set the deactivateCon uniquely for that object. However, when I run the script it seems to set the deactivateCon to the sum of the localDecay values of both game objects; as opposed to setting the deactivateCon to using only the localDecay that is attached to this particular instance. Any help would be much appreciated! :)
using UnityEngine;
using System.Collections;
using System;
using UnityEngine.UI;
public class behButtonDecayManager : MonoBehaviour
{
public int localDecay;
private int deactivateCon = -9000;
private buttonDecayCounter theManager;
private buttonEvents topManager;
public GameObject thisButton;
void Start()
{
theManager = GameObject.Find("Manager").GetComponent<buttonDecayCounter>();
topManager = GameObject.Find("Manager").GetComponent<buttonEvents>();
}
public void setDecay()
{
deactivateCon = theManager.getDecayCounter() - localDecay;
}
void Update()
{
if (deactivateCon >= theManager.getDecayCounter())
{
thisButton.SetActive(false);
topManager.topicCounterBehavior--;
topManager.deactivateTopicBehavior(thisButton);
deactivateCon = -9000;
}
Debug.Log(theManager.getDecayCounter());
Debug.Log(deactivateCon);
}
}
Your answer
Follow this Question
Related Questions
Assign GameObject OnMouseUp not through inspector -2D 1 Answer
What is Casting in Unity ? 1 Answer
How to destroy only the collided instance of prefab and not the original one? 0 Answers
NullException Error while instantiating gameobjects 0 Answers
Check if a large number of gameobjects are colliding 1 Answer