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 Sek19 · Dec 11, 2015 at 03:08 PM · objecttagreferencehierarchy

how to stop tag switching on same object?

So I am having an issue with the way my tag is being referenced, what seems to be happening is that when I look at the object tagged with "Face2" I am being returned on first pass "Face2" (this is what i'm expecting). When moving around the object the return tag switches between the tag "Face2" and "Face1".

On the opposite end I receive no errors when looking at the object tagged with "Face1" So I'm not sure if there is something wrong with the code I have written or if I have set my tags up incorrectly.

My first assumption was that I have a logical error but cant seem to find what it is I'm doing wrong, or that when called out in the code I am referencing this out incorrectly with the way it pulls from the hierarchy.

I have checked and confirmed that changing their position on the hierarchy has not worked.

any help from you is much appreciated!

 using UnityEngine;
 using UnityEngine.EventSystems;
 using UnityEngine.UI;
 using System.Collections;
 
 public class Cameleon : MonoBehaviour, IPointerEnterHandler
 
 {
     public AudioSource Face1_Audio;  // calling from audio source 1
     public AudioSource Face2_Audio;  // calling from audio sourc 2
     float Timer; // timer for amount of gaze time
     public bool Hover = false;
     public void OnPointerEnter(PointerEventData eventData) // is gaze creating a pointerevent
     {   
         GetComponent<Renderer>().material.color = new Color(Random.value, Random.value, Random.value, 1.0f); // assignes the values of random to the new color
  
         string Face = gameObject.tag; // find gameobject that the OnPointerEnter
         Debug.Log(Face);
         Debug.Log("woah");
           
         if (Face == "Face1") // comparing last press event with face_1 if  true then 
         {
 
             Face1_Audio.mute = false; // sound back to original
             Face2_Audio.mute = true;  // mute audio Still play
             Debug.Log("hello,this is face1");
 
         }
         else if (Face == "Face2") // if not face_1 then chack to see if face_2
         {
 
             Face1_Audio.mute = true; // mute audio still play
             Face2_Audio.mute = false;  // sound back to original
             Debug.Log("hello, this is face2");
         }
         else // if neather of these then do nothing
         {
             Debug.Log("neither Face1 or Face2");
         }
 
         //code seems to break right here only when these three lines below are place. 
         string What = EventSystem.current.currentSelectedGameObject.tag; // goes to the event system and finds the tag of the current selected game object
         Debug.Log(What); // refuses to output any information
         Debug.Log("this is the returned string of currentSelectedGameObject"); 
 
         bool Still_there = EventSystem.current.IsPointerOverGameObject(); // looks in EventSystem to see if pointer is on a gameboject
 
         if (Still_there) // looking to see if player is still gazing at the object, if they are do following code
         {
             Timer += Time.deltaTime; // noticed that time only increments when player moves around (think this as something to do with the way OnPointerEnter updates
             Debug.Log("this is on pointer still there");
             Debug.Log(Timer);
             if (Timer == 1.0f)
             {
                 Debug.Log("reached 1.0f");
                 if (Timer >= 1.0f)
                 {
                     Timer = 0.0f;
                 }
             }
         }
         else if (!Still_there) // resets the timer to 0 (never enters this) 
         {
             Timer = 0.0f;
             Debug.Log("this is on pointer not there");
             Debug.Log(Timer);
         }
     }
 }
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
0
Best Answer

Answer by Sek19 · Dec 13, 2015 at 09:12 PM

what the problem was, is that the original game object was duplicated. For some reason the duplicated object was referencing both the Face1 & Face2 tag even though changed in the tag setting. All that needed to be done was create the same gameobject again without duplication and everything runs smoothly.

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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

NullReferenceException: Object reference not set to an instance of an object 0 Answers

Object Reference not set to an Instance 2 Answers

Object reference not set to an instance of an object. 1 Answer

Set reference to multiple gameobjects based on tag category / multiple tags? 2 Answers

Help With LookAt Target 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