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 gamegirl1984 · Sep 03, 2015 at 11:26 PM · if statement

New to IF statements. Need help with playing animation and using IF Statements.

Hello. I have a tv remote that has a small animation on it along with a trigger. When my player looks at the remote it animates and turns on the TV. And then when the player looks at it again it will animate and turn the TV back off. However i'm semi new to scripting. to break it down: I have a quad that has a black texture for (TV OFF) and I have a quad that has a (TV ON) texture.

they are both on the TV and are inactive at the start of the game. when the trigger is hit the TV turn off at first. Then when its hit again the TV turns back on. so on and so forth. So basically i have a script that sets the quads active or inactive when the trigger is hit.... but i have 3 triggers on the remove with a bunch of crazy scripts to get this to work the way i want. And I know there is a much easier solution. (I have triggers activating other triggers, its nuts)

I was wondering if i could use if statements. I never used them and I have no idea how to go about using them with this. I have watched countless videos but I can't seem to figure out what do to.

     (on trigger enter would go here) Then maybe somthing like 
     
         if  (TV is ON turn TV off..........{
             this.transform.GetComponent(Animation).animation.Play("myanimation");
             
             }else{    (if TV is OFF turn TV back ON again????)
                 this.transform.GetComponent(Animation).animation.Stop("myanimation");
 maybe another if statement???
                       ////I would prob. need some var's in there and maybe a boolean???
 
 }


         



I know that is not really a script.

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

Answer by GimLee · Sep 03, 2015 at 11:45 PM

Your tv has two states, on & off.

So the program will first read the: if (TV.isActive == true) // (I don't know how you are toggling it active) If that statement is NOT true, it will perfrom what you've put in "else".

Have you tried this idea of yours? Because the logic is correct in my opinion.

Comment
Add comment · Show 5 · 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 GimLee · Sep 03, 2015 at 11:51 PM 0
Share

One thing though.

line 6: don't put another if statement there, only "else".

If the TV is NOT on, then it can probably only be off I guess. Look at this:

 if (TV is ON) {
      
      TV turn OFF
      doAnimationStuff
 
 }
 else {
 
      TV turn ON
      doAnimationStuff
 
 }
avatar image GimLee · Sep 03, 2015 at 11:53 PM 0
Share

You "ask" the program something in the parenthesis, and if that statement is correct, it will perform the commands between the { }

avatar image gamegirl1984 · Sep 03, 2015 at 11:56 PM 0
Share

Thanks for your quick response. to answer your 1st question I have a trigger on the remote that has a script that sets the object active and also disables the (is trigger) from the trigger. lol, So the quad becomes active via set active true. And covers up the TV ON texture. And that trigger activates a different trigger so that when I hit that trigger the quad becomes inactive via setactive false. Like is said. I have 3 triggers that help me with this buts its a huge pain and i really would like to have one script that does this all. If you saw my mess you would laugh.

And I cannot try my idea because I actually have no idea how to write it in script. I just need some help getting my idea on script. LOL

avatar image GimLee · Sep 04, 2015 at 12:09 AM 0
Share

I'm a little bit confused what the actual problem is then.

In the two statements, you can enable/disable the isTrigger value if you want to. I don't really know what you're asking then. I thought you wanted help understanding if-statements :)

avatar image gamegirl1984 · Sep 04, 2015 at 12:40 AM 0
Share

I'm sorry. I was hoping i could substitue my crazy mess of scripts and triggers to maybe just one script by using if statements. I don't have any. Here is what i have. $$anonymous$$aybe this will show you just how messy and crazy it is. LOL

Just a warning. This is going to be crazy but to be honest this is all i know for scripting and it works. But I would like to know more and make it a bit easier. HEHE I have to go through this every time I want to make something do something. $$anonymous$$y game is taking way longer than it should.

 //// this goes on a trigger attached to the remote
 var remote : GameObject;
 var offanim : String;
 var tvoff : GameObject;
 var Tvlight : GameObject;
 var seconds : float;
 
 var nexttrigger : GameObject;
 
 
 
 
 function OnTriggerEnter (player : Collider){ 
 if(player.tag == "Player")
 
 remote.GetComponent.<Animation>().Play(offanim);
 yield WaitForSeconds(seconds);
 tvoff.SetActive(true);
 Tvlight.SetActive(false);
 nexttrigger.SetActive(true);
 
 
 }
 
 
 
 
 ///// This script goes on yet another trigger that the above script activated...
 
 var trigger : GameObject;
 var seconds : float;
 
 var trigger1 : GameObject;
 var triggeranim : String;
 
 function OnTriggerEnter (player : Collider){
      if(player.tag == "Player")
   trigger1.GetComponent.<Animation>().Play(triggeranim);   
    yield WaitForSeconds(seconds);  
    trigger.SetActive(true);
    
      }  
 
 
 ////////And last but not least, the last trigger, triggers this trigger script. LOL LOL
 
 var remote : GameObject;
 var offanim : String;
 
 var tvOn : GameObject;
 var TvlightOn : GameObject;
 
 var seconds : float;
 
 var trigger : GameObject;
 var triggeranim : String;
 
 var destroy : GameObject;
 var blacktv : GameObject;
 
 
 function OnTriggerEnter (player : Collider){ 
 if(player.tag == "Player")
 trigger.GetComponent.<Animation>().Play(triggeranim);
 remote.GetComponent.<Animation>().Play(offanim);
 yield WaitForSeconds(seconds);
 tvOn.SetActive(false);
 TvlightOn.SetActive(true);
 
 blacktv.Destroy(destroy);
 
 
 }

and now i can't turn my TV back on because I would have to make a bunch more scripts and triggers. But I bet someone knows how i could take all that and make one script by using IF Statements and maybe a few other things I have no idea how to use.

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

28 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

Related Questions

How to put an if statement inside an if statement? 3 Answers

Unity Update is ignoring the GetKey part of my statement!? 2 Answers

If/elseif code doesn't seem to work 1 Answer

'If' order of slider clamps sort-of works? 0 Answers

Switch statement for loot table instead of if statements. 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