- Home /
Problem vid GuiTexture
Hello! I have a problem with my paper popup script. When I walk up to a paper, a text pops up "[E] Read note", when pressing "E" a GuiTexture pops up, and when you left click it closes.
The problem I have is when there's multiple notes around the map. It seems that I can only pick up one note, because when I try to pick up a second one, it just disappears.
Does anyone no what the problem is?
//Paper.js
private var buttonInRange = false;
var note : AudioClip;
public var popupObject : GameObject;
public var guiSkin : GUISkin;
private var popupScript : PaperPopup;
function Start ()
{
popupScript = popupObject.GetComponent(PaperPopup);
}
function OnTriggerStay (c : Collider)
{
buttonInRange = true;
}
function OnTriggerExit (c : Collider)
{
buttonInRange = false;
}
function OnGUI()
{
if(buttonInRange == true)
{
GUI.skin = guiSkin;
GUI.Label (Rect (Screen.width/2-50, Screen.height/2-55, 120, 50),"[E] Read note");
}
}
function Update ()
{
print(gameObject+" buttonInRange = "+buttonInRange);
if(buttonInRange == true)
{
if (Input.GetKeyDown ("e"))
{
print(popupScript+" is showing");
AudioSource.PlayClipAtPoint(note, transform.position);
popupScript.Show();
Destroy (gameObject);
}
}
}
//PaperPopup.js
public var paperObject : Texture2D;
function Start()
{
Hide();
}
function Hide()
{
guiTexture.enabled = false;
}
function Show()
{
if (!guiTexture.enabled)
{
var rect = Rect( -paperObject.width/3, -paperObject.height/2, paperObject.width, paperObject.height );
guiTexture.pixelInset = rect;
guiTexture.texture = paperObject;
guiTexture.enabled = true;
}
}
function OnMouseDown ()
{
Hide();
}
What do you mean by
when I try to pick up a second one, it just disappears
Which note disappears, what happens?
If I have a second note somewhere in the world and try to pick it up, the note disappears and the GuiTexture doesn't show up as it did with the first note. It seems that "Note1" (image above) only shows the Texture. It doesn't matter witch note you choose to read first, you can only read "Note1".
The only thing that seems odd to me is the call to Destroy() but I don't think that should cause your problem. Perhaps try commenting out that line though?
Still wont show. Shows everytime on "Note1" but not on the other ones.
silly question, but can you verify the other note objects have the scripts attached and enabled?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Collecting paper won't work 1 Answer
Show GUITexture by picking an item. 0 Answers
Unity Web player doesn't finish the install, can you please help me? 0 Answers
Tutorial level 2 Answers