- Home /
Spawn Object If Boolean Equals True, Boolean Set To True On Level Load
Not sure what I messed up on here, but I know I messed up on something because the script isn't working. Any help would be appreciated, thanks.
#pragma strict
var belt : GameObject;
var champ : boolean = false;
function Start ()
{
DontDestroyOnLoad (transform.gameObject);
}
//Give Belt
function OnLevelWasLoaded (level : int)
{
if(champ == true)
{
if(Application.loadedLevel == 7)
{
givebelt ();
}
}
}
function Update ()
{
if(Application.loadedLevel == 8)
{
champ = true;
}
}
function givebelt ()
{
var object = Instantiate(belt, Vector3 (0, 0, 0), Quaternion.identity);
object.transform.parent = transform;
}
You're setting champ true on Level8 but giving the belt on Level7? Did you mean if(Application.loadedLevel == level)
or 8
ins$$anonymous$$d if(Application.loadedLevel == 7)
Answer by willparsons · Sep 09, 2015 at 11:39 AM
Firstly make sure you haven't set it to true in the inspector, secondly look through your script where you actually set the boolean to true. In your update function you check if the loaded level is equal to 8, perhaps it actually is.
Your answer
Follow this Question
Related Questions
Better way to delay a function for a few seconds? Javascript 1 Answer
Can See Target not working 1 Answer
Changing Colour of an Object With a GUI.Button Back to Original 0 Answers
Array with boolean variables? 3 Answers
How to smooth between values? 2 Answers