Hi there,
I’m having some trouble with a toggle button =). What I want to do with the button is pretty simple (at least I thought). When toggled on, it triggers a function in the Spawn scriptfile. The function should run until the toggle is triggered again. Here is my code so far, that unfortunately crashes unity on execution:
GUI_dev Script
void Update()
{
if (spawn != spawnToggle)
{
if (spawn == true)
{
action = "spawn";
playerHQ.spawnUnit();
}
else
{
action = "none";
}
spawnToggle = spawn;
}
}
void OnGUI ()
{
spawn = (GUI.Toggle(new Rect(10, 10, 150, 50), spawn, "Spawn"));
}
Spawn Script
public static void spawnUnit(GameObject player, GameObject unit)
{
while (GUI_dev.action == "spawn")
{
//Select place to spawn
}
}
I know that this is most likely a programming issue (I just got started with C#), but I hope somebody can give me a hint how to do this in a correct, elegant way, or at least point me to a website with a solution =).
Thanks in advance,
Thomas
PS: Can anybody recommend the “Beginning C#” tutorials in the Unity Creative magazine?