- Home /
if statement not working
var Enemy : GameObject;
var Spawn_Enemys : GameObject;
var SpawnPosition : Transform;
var isCreated: boolean;
function Start ()
{
isCreated = false;
}
function OnTriggerEnter (Spawn_Enemys : Collider)
{
if (isCreated = false)
{
//Spawns enemy
Instantiate(Enemy, SpawnPosition.transform.position, SpawnPosition.transform.rotation);
isCreated = true;
}
}
what are you using to call OnTriggerEnter? What do you have colliding with your trigger? I suspect that's your problem, not your if statement.
Answer by zwacky · Jun 10, 2011 at 11:59 PM
if (isCreated = false)
to
if (isCreated == false)
That is the problem. To add context to it though, whenever you are assigning a value (say, you want to SET iscreated equal to false) then you use an equals sign. If you want to check the value, use the double equal sign.
Your answer
![](https://koobas.hobune.stream/wayback/20220612102902im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Having trouble checking if the player is in a trigger. 2 Answers
Use of boolean functions in c# 1 Answer
spawning problem 1 Answer
[C#] How to spawn multiple objects that share the same base-class 1 Answer
If multiple triggers activated 1 Answer