Ive created a foreach loop to do what it naturally does, go through the array of objects. My issue is that it wont accept a boolean.
From my understanding if you create a loop with a GameObject:
foreach(GameObject loopObject in loopObjects)
{
loopObject.boolVariable = false;
}
It gives me an error when doing it like that. If I dont add loopObject variable beforehand, I get no response at all.
Does this make sense? If so, how do I work around this?
Basically, what this is, is an array of objects. If just one of them makes collision with the player, they all stop until the one object that made collision is done animatiing, they all will continue as a group.
void Start() { buckets = GameObject.FindGameObjectsWithTag("buckets"); }
void Update()
{
if(stopObject == false)
{
transform.Translate(Vector3.forward * Time.deltaTime);
animation.Play("move");
}
if(stopObject)
{
stopTimer -= Time.deltaTime;
if(stopTimer <= 0)
{
foreach(GameObject bucket in buckets)
{
stopTimer = timerReset;
bucket.collider.enabled = true;
stopObject = false;
}
}
}
if(transform.position.x >= 4f)
transform.position = new Vector3(-3f, 4.34f, 2.45f);
}
void OnTriggerEnter(Collider collision)
{
if(collision.gameObject.tag == "Player")
{
foreach(GameObject bucket in buckets)
{
stopObject = true;
}
animation.CrossFade("dump");
collider.enabled = false;
}
}