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 /
avatar image
0
Question by kuchkuch2000 · Jan 15, 2015 at 05:44 AM · javascriptguierrortrigger4.6

4.6 Trigger.js Wrong command is running. Help?

I'm having problems with a script I created called Trigger.js. The script is suppose to show a GUITexture, buttons, and tell whether you won or lost. If the Opponent passes the finish line first, it is suppose to show "You Lost". If the player wins, it is suppose to show "FINISHED" GUI Texture. Problem is when the Player passes the finish line, it runs the wrong command so it shows "You lost" instead of "FINISHED". The opponent has the tag "Opponent" and the Player has the tag "Player". Here is the script:


 var finished : boolean = false;
 var FinishedTexture : Texture2D;
 var Car = GameObject;
 var lost : boolean = false;
 var MainMenuLevel : String;
 var RestartLevel : String;
 var NextLevel : String;
 
   var LostText : String;   var style
 : GUIStyle;
 
   function Start(){
        Screen.showCursor = false;   }   
 function OnTriggerEnter(Col : Collider)   {      
 Debug.Log("Finished!");      
 if(GameObject.Find("Opponent").CompareTag("Opponent")){
           lost = true;
           yield WaitForSeconds(5);
           Application.LoadLevel(RestartLevel);
       }else{
           finished = true;       }
         
         
                if(finished)       {    
 
           OnGUI();
           Screen.showCursor = true;
                }   }
     
 
   function OnGUI()   {      
 if(GameObject.FindGameObjectWithTag("Player")){
           if(finished) //Means If finished is true
           {
               GUI.Label (Rect (475, 40, FinishedTexture.width,
 FinishedTexture.height/2 - 150),FinishedTexture);
             
             
               if(GUI.Button (Rect (Screen.width/2 -
 150,Screen.height/2, 300, 40),"Restart")){
             
                   Debug.Log ("Restart button works");//Test to see if button work
         
                 //Reloads the Scene Level \/
                   Application.LoadLevel(RestartLevel);
               }
               if(GUI.Button (Rect (Screen.width/2 -
 150,Screen.height/2 - 100, 300, 40),"MainMenu")){
                   Debug.Log("MainMenu Button works!");
                   Application.LoadLevel(MainMenuLevel);
               }
               if(GUI.Button (Rect (Screen.width/2 -
 150,Screen.height/2 - 50, 300, 40),"NextLevel")){
             
                   Debug.Log ("Next Level Button Works!");//Test to see if button
 works
         
                 //Reloads the Scene Level \/
                   Application.LoadLevel(NextLevel);
               }
 
           }       }       if(lost)       {
           GUI.Label (Rect (300, 40, Screen.width/2 - 150, Screen.height/2 -150), LostText, style);       }
        }


What the opponent is: alt text

Here is what happens when I pass the finish line first.

alt text

Script vars:

alt text

If anyone knows how to fix this, please help.

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

2 People are following this question.

avatar image avatar image

Related Questions

JavaScript OnGUI GuiSkins aren't working, multiple scripts 1 Answer

Basketball Score counter 1 Answer

Unity v4.6 Joystick? 2 Answers

Get status of GUI Button 4.6 2 Answers

How do I use a trigger to change the GUIText 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