Hello Devs,
I've a projectile with rigidbody and sphere collider and an enemy with collider (is triger Checked) and with tag "enemy"..
what I want is when the projectile collides with enemy .. enemy should destroy
I'm using this code for Projectile:
public class Projectile : MonoBehaviour {
public float ProjectileSpeed = 10f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
float amtToMove = ProjectileSpeed * Time.deltaTime;
transform.Translate (Vector3.up * amtToMove);
if(transform.position.y >= 4.7f)
{
Destroy(gameObject);
}
}
void onTriggerEnter(Collider other)
{
if(other.gameObject.tag == "enemy")
{
Enemy enemy = (Enemy)other.gameObject.GetComponent("Enemy");
enemy.SetPositionAndSpeed();
Destroy(other.gameObject);
Destroy(gameObject);
}
}
But still got no luck ... any Help is much appreciated.
Best..
.J
↧