I’m trying to make my grenades explode when they come in contact with something. I’ve attached my scripting for Collisions and Shooting just in case my error is in both:
Collisions:
static var GRENADE_AMMO = 0;
function OnControllerColliderHit(hit : ControllerColliderHit)
{
if(hit.gameObject.tag == “crateGrenade”)
{
//destroy the ammo box
Destroy(hit.gameObject);
//add ammo to inventory.
GRENADE_AMMO += 8;
print(“YOU NOW HAVE “+ GRENADE_AMMO +” GRENADES”);
GameObject.Find(“g_Count”).guiText.text = “”+GRENADE_AMMO;
}
}
Shooting:
var speed = 3.0;
var grenadePrefab:Transform;
function Update()
{
//find out if a fire button is pressed
if(Input.GetButtonDown(“Fire1”))
{
if(Collisions.GRENADE_AMMO > 0)
{
//create the prefab
var grenade = Instantiate(grenadePrefab,transform.position,Quaternion.identity);
//add force to the prefab
grenade.rigidbody.AddForce(transform.forward * 2000);
Collisions.GRENADE_AMMO -= 1;
print(“YOU NOW HAVE “+ Collisions.GRENADE_AMMO +” GRENADES”);
}
}
}
In the inspector, I can see in the grenade I’ve set the grenade script on it and the explosion is set to Transform. Seriously perplexed. Thanks for the help!