Hi, i have a gun with the script playerAttack.js . When i left click with mouse i shoot a bullet in front of me. But i want this Insantiate’ed object to be destroyed when it tuch something. When it hit’s a enemy with tag"Enemy" the enemy looses help.
var Bullet : Transform;
var BulletSpeed : float = 100.0;
var BulletDamage : float = 10;
var reloadTime : float = 5;
var curHealth : int = gameObject.GetComponent(enemyHealth);
BulletSpeed = BulletSpeed * Time.deltaTime;
reloadTime = reloadTime * Time.deltaTime;
function Update ()
{
if(Input.GetMouseButtonDown(0))
{
var bullit = Instantiate(Bullet,GameObject.Find("spawnpoint").transform.position,Quaternion.identity);
bullit.rigidbody.AddForce(transform.forward * 10000);
}
}
function OnCollisionEnter (Bullet : Collision) {
if(Bullet.gameObject.tag == "Enemy"){
Destroy(gameObject.FindObjectWithTag == "bullet");
curHealth -= 10;
}
}
THX