If statement not working
I'm having an issue with a script I'm working on. I have made it so that when the character enters a certain collider, the boolean is set to true, but when it is true, the character won't instantiate the cube that i set within the variable. I'm pretty sure it's a mistake in my coding, but I don't know exactly what I'm doing wrong. #pragma strict
var fireball : GameObject;
var ShootFireballs = false;
function Start () {
}
function OnTriggerEnter (Other : Collider){
if(Other.gameObject.tag == "fireflower"){
ShootFireballs = true;
}
}
if (ShootFireballs == true) {
if(Input.GetKeyDown(KeyCode.E))
Instantiate(fireball, transform.position, Quaternion.identity);
}
Comment
Is your if statement inside of update? from the code you posted it's not within a function.
Answer by Gobaz · May 28, 2016 at 09:02 AM
Try this:
var fireball : GameObject;
var ShootFireballs = false;
function Start () {
}
function OnTriggerEnter (Other : Collider){
if(Other.gameObject.tag == "fireflower"){
ShootFireballs = true;
}
}
function Update(){
if (ShootFireballs == true) {
if(Input.GetKeyDown(KeyCode.E))
Instantiate(fireball, transform.position, Quaternion.identity);
}
}
}