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 /
  • Help Room /
avatar image
0
Question by unity_9rZ2tQdXui6bvw · Oct 02, 2020 at 08:40 AM · gameobjectinspectoractivereferencingfindobjectoftype

I have prefabs that should be referencing different GameObjects, but they all refer to the same one.

In my game I have a simple prefab of a cube. On this cube I have a Script called "Lore". And a box collider 3x the size of the cube that I have made into a trigger and given the tag "Lore". That is all. Underneath my cube prefab (as a child) I have created a Canvas called "Message". So every single Cube prefab has a collider, Lore script. and a Canvas called Message.

In my PlayerMovement script I have created an OnTriggerStay() so that when I walk into the "Lore" trigger it calls upon another function. Like so:

 private void OnTriggerStay(Collider other) 
 {
 if (other.tag == "Lore")
         {
             Debug.LogError("Inside Letter Box");
             FindObjectOfType<Lore>().ClickEToPickUpLetter();
         }
 }

Therefore the entie time I am inside of the "Lore" Trigger it is recalling FindObjectOfType().ClickEToPickUpLetter(); Over an Over.

The function it is calling looks like this.

  public GameObject loreMessage;
 
 
 public void ClickEToPickUpLetter()
     {
         if (Input.GetKeyDown("e"))
         {
                loreMessage.SetActive(true);
         }
     }

In this case. While I am in the trigger, if The user Clicks "e" my GameObject loreMessage is being set to active. In my inspector I referenced the CANVAS that I made as my loreMessage. So that every time the user clicks "e" my Message Canvas is being set to active. here is my problem. When i walk into the trigger "Lore" I have a Debug.Log that says "Inside Letter Box" so i know that my trigger is working. I have also put a Debug.Log into my ClickEToPickUpLetter() Function. So i know that function is being called aswell when the user clicks "e". My problem is that the GameObject that is being turned on (In my case loreMessage, as in my Canvas) is the same canvas every single time.

I have this prefb placed over multiple parts of the map. And each object has a lore script with the same collider. The only difference is that on each object i have referenced a different canvas, so that when the user clicks "e" a new canvas opens up , dislaying a new image. Why is the same canvas being referenced every time the script is called even though each individual script has reference to a different canvas/GameObject. is this because it is a prefab? All i am trying to accomplish is simply walking up to a trigger. In this case "Lore" being able to press "e" on top of it. And when the user presses the button a new canvas is being opened. every time they enter a new collider. But it doesnt seem to be opening the game object i have referenced in the inspector. Instead it opens the first canvas i originally created every time. Thanks any answers are much appreciated.

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

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

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

Cannot figure out GetComponent for the life of me 1 Answer

GameObject SetActive not reactivating 5 Answers

Scrpits component disappears when I enter playmode 0 Answers

Is there a way to refer to the only script the object has without naming the script? 2 Answers

How do I fix my code so that these If statements turn an object off or on depending on a number 2 Answers


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