- Home /
Question by
CrilleStyles · Aug 07, 2014 at 08:31 AM ·
arrayaibooleandrop
My AI drops stuffs on death even when not supposed to
How to I make that my AI will drop only if the boolean is true? I got my code here and I'm still learning booleans and arrays.
#pragma strict
var thisObject : Transform;
var Health = 100;
var tombstone : GameObject;
var WillDrop : boolean = false;
var ObjectToDrop : GameObject[]; //[] means that you can use more than one objects
function Start()
{
WillDrop = Random.value < 0.10; //Dropchance of 10%
}
function ApplyDammage (TheDammage : int)
{
Health -= TheDammage;
if(Health <= 0)
{
Dead();
}
}
function Dead()
{
if(WillDrop == true);
var obj : GameObject = ObjectToDrop[Random.Range(0, ObjectToDrop.length)]; //Randomize a prefab to drop between Medkit, ammobox and AllInOne kit
var pos: Transform = thisObject;
Instantiate(obj, pos.position, pos.rotation); //Spawn prefabs
Instantiate (tombstone, gameObject.transform.position, Quaternion.identity); //Spawn tombstone (Baloons)
Destroy (gameObject);
if (WillDrop == false);
Instantiate (tombstone, gameObject.transform.position, Quaternion.identity); //Spawn tombstone (Baloons)
Destroy (gameObject);
}
Comment
Best Answer
Answer by thornekey · Aug 07, 2014 at 08:42 AM
if(WillDrop == true) {
var obj : GameObject = ObjectToDrop[Random.Range(0, ObjectToDrop.length)]; //Randomize a prefab to drop between Medkit, ammobox and AllInOne kit
var pos: Transform = thisObject;
Instantiate(obj, pos.position, pos.rotation); //Spawn prefabs
Instantiate (tombstone, gameObject.transform.position, Quaternion.identity); //Spawn tombstone (Baloons)
Destroy (gameObject);
}
if (WillDrop == false) {
Instantiate(tombstone,gameObject.transform.position, Quaternion.identity); //Spawn tombstone (Baloons)
Destroy (gameObject);
}
its not the boolean that is the problem. Its your if statement. If statements are much like methods. You need the curly brace at the end of them. Not a semi-colon.