- Home /
Script on two objects only runs as a single instance?
The following script:
enter code hereIEnumerator observe ()
{
while (true)
{
yield return new WaitForSeconds (0.3f);
Debug.Log ("Detecting");
Collider[] colliders = Physics.OverlapSphere (transform.position, stasisRange);
foreach (Collider collider in colliders)
{
if (collider.transform.position.magnitude <= awarenessRange)
{
AddSubscriber (collider.gameObject);
}
else
{
RemoveSubscriber (collider.gameObject);
}
}
}
}
Runs correctly when on object A and not on object B. Runs correctly when on object B and not on object A. When on object A and B only runs as though it is on object A.
Why is this?
Thanks in advance.
Sean
What do AddSubscriber and RemoveSubscriber methods?
When this coroutine is called?
Can you show us more of your script ? Its hard to tell just from looking at a method.
The question is not about the script, the script works fine. I just need to know why the script only runs once per scene, or seems to be rather. There is no script I could provide that would further help the question.
Answer by KMKxJOEY1 · Oct 09, 2014 at 08:35 PM
Your comment is incorrect. To further help this question, there are plenty of things that could be included. The most obvious option here would be the context of invocation of the routines, as you are probably calling them in a weird way for this behavior to be happening.
Answer by Geneon · Oct 09, 2014 at 11:42 PM
@Tourist @AjayKhara @KMKxJOEY1
I apologize, ironically if I showed you all my code you could have told me that the reason it doesn't work on two objects is because it is implemented within a class this is a singleton...
I'm an idiot and i am sorry.
Sincerely, Sean
Your answer
![](https://koobas.hobune.stream/wayback/20220613164657im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Learning Unity Methods 1 Answer
Multiple Cars not working 1 Answer
A node in a childnode? 1 Answer
Where to use Structs and classes? 5 Answers
Distribute terrain in zones 3 Answers