- Home /
Edit String of instantiated Object then save it.
First Post!
I have a user instantiating an object at the location they are looking using ray casting. Once the object is placed they can click on it which opens a GUI box were they can input text into a string.
Here is the problem: After I instantiate one I can click on it and edit the string, no problem. After the second one is placed. I can click on it, and it opens the for mentioned GUI text box, i enter text into the text box, and it changes the string for the first one i created, leaving the second still set to null.
Code:
function OnGUI()
{
if(editingHotspot == true)
{
//The Box
GUI.Box(Rect(0,0,Screen.width+10,Screen.height+10),"Hotspot Editor");
//Exit Button
if (GUI.Button(Rect(Screen.width/2 - 150,Screen.height/2 + 20,120,30),"Save and Exit"))
{
editingHotspot = false;
}
//Name
GUI.Label(Rect(Screen.width/2-400,Screen.height/2-230, 100, 30), "Enter Name:");
hotspotName = GUI.TextField(Rect(Screen.width/2-400,Screen.height/2-200, 200, 25), hotspotName, 40);
}
}
We need to see more of your code. In particular how hotspotName is used and how 'editingHotspot' gets set to true.
How "hotspotName" is used:
//Declaring
var hotspotName : String;
How 'editingHotspot' gets set to true:
function OnGUI()
{
//Checking to see if the users wants to edit Hotspot
if(clicked == true && editingHotspot == false)
{
//Text
GUI.Label(Rect(Screen.width/2,Screen.height/2,200,30),"Edit Hotspot?");
//Yes or No Buttons
if (GUI.Button(Rect(Screen.width/2 - 90,Screen.height/2 + 20,60,30),"Yes"))
{
editingHotspot = true;
clicked = false;
}
if (GUI.Button(Rect(Screen.width/2 + 30,Screen.height/2 + 20,60,30),"No"))
{
clicked = false;
}
}
}
P.S. 'editingHotspot' is a static bool from another script
Answer by Esildorr · Apr 15, 2014 at 07:07 PM
FIXED: the editingHotspot variable was static and because of that ALL of the GUI function were getting triggered to true, causing them to draw over each other. I just never realized it. This is also why i could only change the first one.
Thanks for everybody's time.