- Home /
Enabling a component of a different gameobject c# (halo)
I am trying to enable a halo on a different gameobject on mouse enter of the main object box collider.
I know halo's can be a little weird, script is here:
void OnMouseEnter()
{ if (IsQuit) {
GameObject.Find("epart").particleSystem.enableEmission = true;
GameObject.Find("epart").(GetComponent("Halo")as Behaviour).enabled = true;
} else
GameObject.Find("spart").particleSystem.enableEmission = true;
GameObject.Find("spart").(GetComponent("Halo")as Behaviour).enabled = true;
}
the particle system bit works fine. I managed to get the halo to enable and disable via the second part "(GetComponent("Halo")as Behaviour).enabled = true;" if it is tied to the object itself, but can't figure out how to get this to work from an object that is not the object with the halo as the component.
error message i get from console is:
Assets/Scripts/Menu.cs(25,50): error CS1525: Unexpected symbol (', expecting identifier'
(is duplicated for the line 28,50)
I know it's because the GetComponent just after finding the game object is in brackets, but without the brackets the halo enable does not work.
I would greatly appreciate any help, thank you thank you!
Try creating a variable and setting it equal to GameObject.Find("epart").GetComponent("Halo"), then enable that variable. Same for "spart".
It also looks like you need curly brackets at lines 5 and 7, if you want both those lines contained within the else statement.
I can see how that should do the trick, sorry for my poor coding and stupidity, it's my first day :P
I have looked around for the past 40ish $$anonymous$$utes at how to make a variable and setting it equal to GameObject.Find("epart").GetComponent("Halo"), I can't understand what type of variable that would be, would it be a bool?
Sorry again, and much appreciated with your help.
Just a GameObject should be fine. And no problem, we've all had first days, some of them considerably less impressive than yours, I'm sure!
Lol well that's a plus I guess. I just managed to figure it out without having to set a variable and I feel a little stupid but all I did was this - void On$$anonymous$$ouseEnter() { if (IsQuit) { GameObject.Find ("epart").particleSystem.enableEmission = true; (GameObject.Find ("epart").GetComponent ("Halo")as Behaviour).enabled = true; } else { GameObject.Find ("spart").particleSystem.enableEmission = true; (GameObject.Find ("spart").GetComponent ("Halo")as Behaviour).enabled = true; } }
I simply had my brackets all a bit wacky, but this is working.
Our of curiosity any chance you could give me an example of what that GameObject variable would look like?
Would it look like this - public GameObject = GameObject.Find ("epart").GetComponent ("Halo"); ?
Just good to know and keep learning, thank you again friend, much appreciated.
Glad you figured it out! Yes, that declaration for the GameObject should work.
Your answer
Follow this Question
Related Questions
Enable Draw Halo in Light Component via Script 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Adjusting size of a halo in C# 0 Answers
Enable/disable Halo component in C# 1 Answer