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 Kag359six · Jul 05, 2011 at 07:20 PM · guitexturetriggersdisable

Disabling a gui texture through triggers

The following script allows me to enter a trigger, and will display a gui texture. but i also want the gui texture to dissapear when i exit the trigger. how would i do this? i tried destroying but it destroyed the prefab also... can i somehow disable it? script:

function OnTriggerEnter (PlayerCollider : Collider) { if(PlayerCollider.gameObject.name == "player") {

     var instance : GUITexture = Instantiate(openDoorText,Vector3(.5, .5, 0), Quaternion.identity);
     
     
     }
     
     
     

}

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by GuyTidhar · Jul 05, 2011 at 07:56 PM

You must have been trying to destroy the prefab and not the instance, therefor you should place a variable outside of the scope of the OnTriggerEnter function so you can access it on other functions and in your case OnTriggerExit:

 var guiTexturePrefab : GUITexture;

 var doorUp : AnimationClip; 
 var timer : float = 6.0;
 private var instance: GUITexture;
 
 function OnTriggerStay (mytrigger : Collider) 
 {
     if(mytrigger.gameObject.name == "player" ) 
     {
         door = gameObject.Find("door");
 
         if(Input.GetButton("openDoor"))
             door.animation.Play("hoistDoorUp");
     }
 }

 function OnTriggerEnter (PlayerCollider : Collider) 
 { 
    if(PlayerCollider.gameObject.name == "player") 
       instance= Instantiate(guiTexturePrefab,Vector3(.5, .5, 0), Quaternion.identity);
 }
 function OnTriggerExit (PlayerCollider : Collider) 
 { 
    if(PlayerCollider.gameObject.name == "player" && instance) 
       Destroy(instance);
 }
Comment
Add comment · Show 6 · 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 Kag359six · Jul 05, 2011 at 08:57 PM 0
Share

that works, but when i go back into the trigger, the instance wont come back saying that the object was destroyed. how do i fix that?

avatar image GuyTidhar · Jul 05, 2011 at 09:04 PM 0
Share

Where you actually use the instance, you should check if it exists before using it: if ( instance ) yourFunction();

avatar image GuyTidhar · Jul 05, 2011 at 09:05 PM 0
Share

You are welcome to add that peace of code so I can have a look.

avatar image Kag359six · Jul 05, 2011 at 09:26 PM 0
Share

alright im adding it as an answer, just respond there.and i forgot to add the variables i had at the top. heres the whole page of code, just look at the ontrigger functions.

avatar image GuyTidhar · Jul 05, 2011 at 09:38 PM 1
Share

In the code you posted you are trying to instantiate the instance using the instance - you can not do that. I changed the code here: You should drag the prefab of type GUITexture which you created before run-time into the guiTexturePrefab variable; Then this variable is used to instantiate a new GUITexture each time you call instantiate. Your "instance" variable saves the new created GUITexture and then you can use it.

Show more comments
avatar image
0

Answer by Kag359six · Jul 05, 2011 at 09:27 PM

var doorUp : AnimationClip; var instance : GUITexture; var timer : float = 6.0;

function OnTriggerStay (mytrigger : Collider) {

if(mytrigger.gameObject.name == "player" ) {

 door = gameObject.Find("door");
 

 

if(Input.GetButton("openDoor"))

     door.animation.Play("hoistDoorUp");
 }
 
 

}

function OnTriggerEnter (PlayerCollider : Collider) { if(PlayerCollider.gameObject.name == "player") {

      instance = Instantiate(instance,Vector3(.5, .5, 0), Quaternion.identity);
     
     
     }
     
     
     

}

function OnTriggerExit (playerCollider : Collider) { if(playerCollider.gameObject.name == "player" && instance)

     Destroy(instance);

}

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

Reduce Draw call for Multiple GUI Textures with same Texture 1 Answer

Displaying GUITexture after all triggers activated 0 Answers

If multiple triggers activated 1 Answer

show different textures when trigged entered thrice 2 Answers

Guitexture disable not working second time 0 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