Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Player not getting destroyed when touched by enemies

$
0
0
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); } } }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>