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 /
  • Help Room /
avatar image
0
Question by Sek19 · Dec 02, 2015 at 10:02 AM · referenceif-statementstags

what am I doing wrong in if statement comparison

Hello all and wonderful day to you! I have been writing a script that takes a cube, changes its color with a random one Then is supposed to find a gameObjects tag on the cube. If the cube has face1 as its tag then it should turn Face1_Audio back to original audio volume (unmute). while it turns Face2_Audio to mute. and vise versa for the else if. I'm not sure if I'm calling for the game tag incorrect or if I should be referencing this in another manner with the if statement. As of right now this is unresponsive besides the changing of the color so I have narrowed it down to these if statements. All help or advice 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
     GameObject gameobject;
 
     
 
    
     public void OnPointerEnter(PointerEventData eventData) // is gaze creating a pointerevent
     {
         
         string Face = gameObject.tag;
 
       //  PointerEventData lastPress; // the GameObject for the last press event
          
         GetComponent<Renderer>().material.color = new Color(Random.value, Random.value, Random.value, 1.0f); // assignes the values of random to the new color
 
   
          if (Face == "Face1") // comparing last press event with face_1 if  true then 
             {
          
             Face1_Audio.mute = true; // sound back to original
             Face2_Audio.mute = false;  // mute audio Still play
        
              } 
          else if (Face == "Face2")
         {
 
             Face1_Audio.mute = false; // mute audio still play
             Face2_Audio.mute = true;  // sound back to original
 
         }         
     }
 }
 
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 centaurianmudpig · Dec 02, 2015 at 04:25 PM

You have muted and unmuted audio without trying to Play() it. Also, rather than muting I would use Stop().

Comment
Add comment · Show 8 · 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 Sek19 · Dec 02, 2015 at 09:02 PM 0
Share

I'm sorry I must not have explained This correctly. I do not want to stop the audio due to the fact I need it to play while not heard to keep up with some of the ti$$anonymous$$g. So i feel as though I do not need a Play() as the audio is already playing on loop on start. Now I'm not certain if the Play() is essential to muting if the audio is playing already but what are your thoughts on the matter?

avatar image centaurianmudpig Sek19 · Dec 02, 2015 at 09:20 PM 0
Share

After you have assigned face to the tag, print out the value to console and confirm the value is what you expect. This will also confirm if OnPointerEnter() is being called.

 string Face = gameObject.tag;
 Debug.Log(Face);


avatar image Sek19 centaurianmudpig · Dec 03, 2015 at 06:54 PM 0
Share

thank you for that, So this is what the Console returns.

Cardboard SD$$anonymous$$ object should be a singleton. UnityEngine.Debug:LogWarning(Object)

definitely not what I was expecting as a return. I ended up changing the code to this

  if (Face == "Object")
 
 {
             Face1_Audio.mute = false; // mute audio still play
             Face2_Audio.mute = false;  // mute audio Still play
 
 }


just to see if the audio would turn off. Even with this absolute of Face = Object it does nothing.

Is this because it's not actually returning a string? I'm not sure why it's not returning the actual tag. all objects that the OnPointEvent would hit in scene are marked with tag (Face1) in the inspector.

Show more comments

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to reference a GameObjects Box Collider true in a if statement! 2 Answers

IF Else Statement being ignored ,the else if condtion is being ignored and playing first IF condition for all game objects. 0 Answers

How to find (and remove) references to GameObject C# 0 Answers

Instatiated object not being referenced in Start function? 2 Answers

Getting Int value from script to other script 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