Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by AbysmalHero · Jan 16, 2014 at 04:13 AM · c#componentdifferenthalo

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!

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Quillicit · Jan 16, 2014 at 06:32 AM 1
Share

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.

avatar image AbysmalHero · Jan 16, 2014 at 07:32 AM 0
Share

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.

avatar image Quillicit · Jan 16, 2014 at 07:46 AM 0
Share

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!

avatar image AbysmalHero · Jan 16, 2014 at 08:03 AM 0
Share

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.

avatar image Quillicit · Jan 16, 2014 at 08:32 AM 0
Share

Glad you figured it out! Yes, that declaration for the GameObject should work.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges