Hello! I'm trying to develop my first 2D shooter. I have 3 types of enemies and 3 types of spells which destroys one of the enemies, but if it hits a wrong enemy type just the projectile gets destroyed.
I've been trying to include a destroy script for when the player gets touched by an enemy, but for some reason I can't get it going.
Here is the script for enemy prefab:
using UnityEngine;
using System.Collections;
public class Enemy : MonoBehaviour {
public float EnemySpeed;
private Transform myTransform;
void Start () {
myTransform = transform;
}
void Update () {
float amtToMove = EnemySpeed * Time.deltaTime;
myTransform.Translate(Vector3.left * amtToMove);
if (myTransform.position.x < -10.9f)
Destroy(this.gameObject);
}
void OnTriggerEnter(Collider otherObject)
{
if (otherObject.tag == "Wizzard") {
Destroy (otherObject.gameObject);
Destroy (gameObject);
}
}
}
↧