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

Only damage one object with "Enemy" tag

$
0
0
Im making a tower defense game and i need my cannon to pick a target (first enemy that enters it's range) and shoot at it until it dies while ignoring other enemies, then pick a new target. Right now my turret damages every enemy with the tag "Enemy" that enters it's range. My cannon code: var level = 1; var damage = level; var attackspeed = 1; var isshooting = 0; var currentenemy : GameObject; function Start () { } function Update () { } function OnTriggerEnter (other : Collider) { if(other.gameObject.CompareTag("Enemy")){ print("damaged the enemy"); other.gameObject.SendMessage("OnDamage", damage); } } And my Enemy code: var health=10; function OnDamage(damage:int) { print(damage); health = health - damage; if(health <- 0) { 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>