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 HaruAokii · May 28, 2014 at 04:36 PM · guierrortriggerenter

GUI script problem with trigger enter.

Hello,

Im having problem with a script I'm using with GUI, Its with a door open script when the player enters the trigger a GUI will show up saying "Press 'E' to open the door" when the player leaves the trigger the GUI will go away but if you open the door and then leave the trigger the GUI will not go away and will say up till the player closes the door. Could anyone help please.

Below is the script I'm using.

 var smooth = 2.0;
 var DoorOpenAngle = 90.0;
 private var open : boolean;
 private var enter : boolean;
 
 private var defaultRot : Vector3;
 private var openRot : Vector3;
 
 function Start(){
 defaultRot = transform.eulerAngles;
 openRot = new Vector3 (defaultRot.x, defaultRot.y + DoorOpenAngle, defaultRot.z);
 }
 
 
 function Update (){
 if(open){
 
 transform.eulerAngles = Vector3.Slerp(transform.eulerAngles, openRot, Time.deltaTime * smooth);
 }else{
 
 transform.eulerAngles = Vector3.Slerp(transform.eulerAngles, defaultRot, Time.deltaTime * smooth);
 }
 
 if(Input.GetKeyDown("e") && enter){
 open = !open;
 }
 }
 
 function OnGUI(){
 if(enter){
 GUI.Label(new Rect(Screen.width/2 - 75, Screen.height - 100, 150, 30), "Press 'E' to open the door");
 }
 }
 
 
 function OnTriggerEnter (other : Collider){
 if (other.gameObject.tag == "Player") {
 enter = true;
 }
 }
 
 
 function OnTriggerExit (other : Collider){
 if (other.gameObject.tag == "Player") {
 enter = false;
 }
 }

Thank you for reading my post and I hope you have a great day.

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 zharik86 · May 28, 2014 at 06:43 PM

As far as I understood, after door opening, the message that he closed a door shall be always visible to the player. Independent, whether to be the player in a zone of this door or not. If so, simply add in GUI:

  function Start() {
   defaultRot = transform.eulerAngles;
   openRot = new Vector3 (defaultRot.x, defaultRot.y + DoorOpenAngle, defaultRot.z);
   //Init open variable
   open = false; //door is not open - state close
  }

  function OnGUI() {
   if(enter && !open) {
    GUI.Label(new Rect(Screen.width/2 - 75, Screen.height - 100, 150, 30), "Press 'E' to open the door");
   } else if (open) {
    GUI.Label(new Rect(Screen.width/2 - 75, Screen.height - 100, 150, 30), "Close door");
   }
  }

I hope it to you will help.

Comment
Add comment · Show 1 · 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 HaruAokii · May 29, 2014 at 08:56 AM 0
Share

This scripted only replaces the problem with "Close door" on the screen at all times when the door is open.

I won't it so if the player opens the door then walks away the "Press 'E' to open the door" is not on the screen I don't won't any GUI on the screen when the door is open and the payer is off the trigger. But thank you anyway for trying to help.

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

22 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

Related Questions

4.6 Trigger.js Wrong command is running. Help? 0 Answers

Loading a scene in game with a GUI 1 Answer

Trigger GUI working wrong 1 Answer

activate gui on trigger enter 1 Answer

OnTriggerEnter problem 3 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