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);
}