|
Hello, I'm trying to find objects with a certain tag then disable one specific script inside those objects but cannot manage to make it work so far. Here is what I was trying lately: Can someone explain me what is going on here and why I cannot do such a thing ? Thank you very much! :) Phil
(comments are locked)
|
|
First, FindGameObjectsWithTag returns a list of objects. Second, you need to loop through all those objects. Third, you need to get the BlockFall component from each object and set its enabled property to false. Deleted my nearly identical answer but yes, you're getting an array, not a single object out of FindGameObjectsWithTag
Jul 26 '11 at 09:25 PM
Chris D
(untested) code added.
Jul 26 '11 at 09:27 PM
almo
Thanks!! :) I want to place the "for" into a function like "OnMouseDown" and it says that to me: UnityException: You are not allowed to call this function when declaring a variable. Move it to the line after without a variable declaration. If you are using C# don't use this function in the constructor or field initializers, Instead move initialization to the Awake or Start function. BlockDrag..ctor () (at Assets/BlockDrag.js:5) ArgumentException: FindGameObjectsWithTag can only be called from the main thread. Constructors and field initializers will be executed from the loading thread when loading a scene. Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function. BlockDrag..ctor () (at Assets/BlockDrag.js:5) I'll try something else and tell you how it goes. UPDATE: Well, is there any way of disabling multiple components at once without using the "FindGameObjectsWithTag" ? I can't seem to get anything working while using a function that triggers on mouse button down... (-_-)
Jul 27 '11 at 05:20 PM
pcote
Can you post the exact code you're using? Might be able to help you figure it out.
Jul 27 '11 at 05:38 PM
Chris D
What you should do is get this working so you can turn them off, not using mousedown. Triggering a function on mousedown would then be another question you would ask. Break your tasks into bits, or Unity Answers won't be able to help you.
Jul 27 '11 at 05:46 PM
almo
(comments are locked)
|

You have 3 open questions here, two of which have answers. If you get a useful answer, you're supposed to "accept" it by clicking the checkmark by the answer that helped.
Thanks. I didn't notice the check. Also, I didn't have time to test your answer. I'll do that today, probably. :)
No problem. :) It's not entirely obvious how this site works when you first show up.