- Home /
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");
}
}
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");
}
}
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?
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.
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!
Just this is fine:
Instantiate(sharkDead, new Vector3(.5f, .5f, 1f), Quaternion.identity);
Your answer
Follow this Question
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