My projectile


I also have it destroy if it hits anything or goes more than 100 meters.
It also ignores the game object shooting it.

void Update ()
{
    if (Vector3.Distance(StartLocation, transform.position) > 100)
        Destroy(gameObject);
}

void OnTriggerEnter(Collider otherCollider)
{
	print(otherCollider.ToString());

    if (otherCollider.gameObject == ObjectFrom)
        return;

	Component damageable = otherCollider.gameObject.GetComponent(typeof(IDamagable));

	print(damageable);

	if (damageable)
	{
		(damageable as IDamagable).TakeDamage(Damage);
	}

    Destroy(gameObject);
}

Privacy & Terms