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 05:44 PM · instantiatetriggerguitextureinstanceonce

how to instantiate GUI Texture

I'm trying to instantiate a GUITexture only once, and only if the player is in the trigger box that i made. However when i instantiate with the following script it keeps making copies since im in the trigger constantly. How do i instantiate my guitexture once? script: var doorUp : AnimationClip; var openDoorText : GUITexture;

function OnTriggerStay (mytrigger : Collider) {

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

 door = gameObject.Find("door");
 var instance : GUITexture = Instantiate(openDoorText, transform.position, Quaternion.identity);

 

if(Input.GetButton("openDoor"))

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

}

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 GuyTidhar · Jul 05, 2011 at 06:04 PM

Why not use OnTriggerEnter? This is called only once you enter the collider.

 function OnTriggerEnter (mytrigger : Collider) 
 {
 
   if(mytrigger.gameObject.name == "player" ) 
   {
      door = gameObject.Find("door");
      var instance : GUITexture = Instantiate(openDoorText, transform.position, Quaternion.identity);
 
      if(Input.GetButton("openDoor"))
        door.animation.Play("hoistDoorUp");
    }
  }
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 Kag359six · Jul 05, 2011 at 06:33 PM 0
Share

Alright its instantiating once but its not showing up on my screen during gameplay. how do i give it coordinates on my gameplay screen so it actually shows up?

avatar image aldonaletto · Jul 05, 2011 at 06:57 PM 1
Share

GUITexture coordinates are different: they range from 0 to 1 in both horizontal and vertical directions. Use this:

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

$$anonymous$$odify the values 0.5 and 0.2 to change the GUITexture position in screen if needed.

avatar image st362 · Jan 25, 2013 at 05:38 AM 0
Share

How is this done in C#? Having trouble with it. I have:

GUITexture deadShark = (GUITexture)Instantiate(sharkDead, new Vector3(.5f, .5f, 1f), Quaternion.identity);

gives me an error: Cannot cast from source type to destination type.

Please help! Thanks!

avatar image raptorkwok · Mar 06, 2014 at 07:02 AM 0
Share

Just this is fine:

 Instantiate(sharkDead, new Vector3(.5f, .5f, 1f), Quaternion.identity);
avatar image st362 · Mar 06, 2014 at 04:09 PM 0
Share
  • raptorkwok

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Show GUI Texture on Trigger and Instantiate Object if Button pressed while In Trigger? 1 Answer

destroying instructions sequence 1 Answer

i need to copy a list from the collided to the newly instantiated one individually . 0 Answers

Want a script that can instantiate an object when MOVING inside the trigger 1 Answer

Instantiate Prefab At Collided Object? 1 Answer


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