How to use FindGameObjectsWithTag to return individual components
I have a short horror game that I am making in which the player can use throwable objects to distract the enemy. The distraction system worked well when I only had a single throwable in the game, but now that there are a few, some issues have arisen.
In short, each throwable object has a short script on it identifying if it has collided with the ground (from the player throwing it) and saves the location of the collision.
The AI script checks to see if any throwable objects have triggered a noise, and if they have, if it is within its range of "hearing".
The game compiles without errors, and each individual object's Distraction System is working (triggers that noise is made), however, when I throw an object, the "DistractionTrigger" is not checked within the Inspector. I believe it has something to do with the reference to the distraction system, but I am not one hundred percent sure. Any help would be greatly appreciated. :)
Here is the relevant code:
This is in the Start() method:
foreach(GameObject Throwable in throwableObjects){
Debug.Log(Throwable);
distraction = Throwable.GetComponent<DistractionSystem>();
}
This is in the Update() method:
foreach(GameObject Throwables in throwableObjects)
if (distraction.noiseMade == true && Vector3.Distance(distraction.location, transform.position) <= distractedRange)
{
distractedSearch = distraction.location;
distractionTrigger = true;
}