Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 marx13maxz · May 18, 2018 at 10:21 AM · gameobjectgetcomponentgetcomponents

How to look for a game object and a change some components on that object?

Lets say I have 3 images; image1, image2 and image3. and 3 boxes, box1, box2, and box3. If I click image1 first it will go to box1, then image2 to box2 and image3 to box3. On another run, if I click image2 first, it will go to box1, then next image to box2 and next image to box3. So now, the problem or what I want to really happen now is if I click box1 or any other box, the image in box1 should return to the image where it originally belong. say, box1 has image2 so when I click box1, image2 will return to its original state.

PS: I am a beginner in UNITY so please bare with me. I appreciate some answer. and I apologize if my question has already been asked just provide me the link to the answer. Thank you so much.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by KaspianR · May 18, 2018 at 10:33 AM

I can't really help you with creating that mechanic since it's to much to do inside of just scripts but I can help you with finding the object: GameObject.Find("The name of the object") will give you the object with that name. And you can use GameObject.Find("The name of the object").GetComponent<The component you wan't to use>() to find the component you need. This is one way to do it but if you want an easier way you can just make a public variable of type GameObject (Transform would work as well). And then just drag your Image/Box to the slot that appeared in the inspector! Is this what you wanted?

Comment
Add comment · Show 4 · Share
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 marx13maxz · May 18, 2018 at 10:49 AM 0
Share

Thank you @$$anonymous$$aspianR , I stored the gameObject.name to a string, say name1, and use name1 in GameObject.Find(name1).GetComponent< my component to use>() but it returned a NullReferenceException: Object reference not set to an instance of an object ClickControl.On$$anonymous$$ouseDown ().

avatar image KaspianR marx13maxz · May 18, 2018 at 11:07 AM 0
Share

Did you replace "my component to use" with the component you wanted to find? If you want to find a specific script you can just write the name of that script and if you need the position you can use GameObject.Find(name1).transform.position If this still doesn't work please provide a bit more information about what component you want to change and how!

avatar image marx13maxz · May 18, 2018 at 11:08 AM 0
Share

Never$$anonymous$$d, it worked! there was just some error in my code. Thank you so much!

avatar image KaspianR marx13maxz · May 18, 2018 at 11:12 AM 0
Share

No problem, glad I could help!

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

126 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 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 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 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 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 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 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

GameObject.Find GetComponent C# 4 Answers

how to access a float from one script in other script in different objects 3 Answers

How to run a function in a GO that have DontDestroyOnLoad 1 Answer

How to Access Components in Children of GameObject? 1 Answer

Deactivate Script 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