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

How to use 1 script for multiple enemies ?

$
0
0
I want to make multiple enemies with 1 script, if I just duplicate the prefab with attached script, 1 die, all will die. How can I make it with just 1 script, so don't need multiple script ? My script : static var health : int; var playerDistance : int; static var player : GameObject; static var attacking : boolean = false; var attackEffect : AudioClip; var move : boolean = true; var isdead : boolean = false; static var hurt : boolean = false; var target : Transform; var aware : boolean = false; var character : GameObject; var agent : NavMeshAgent; function Update(){ if(hurt){ if(health > 0){ TakenDamage(); //reducing enemy health } } playerDistance = Vector3.Distance(player.transform.position, transform.position); if(playerDistance <= 1){ if(!attacking && health > 0 && !hurt){ move = false; GetComponent.().Stop(); animAttack(); //attacking } } if(playerDistance > 1 && playerDistance <= 25 && !attacking && this.health > 0 && !hurt){ agent.destination = target.transform.position; agent.Resume(); if(!aware){ animMove(); //moving } if(aware){ run(); //running } } if(playerDistance > 25 && health > 0){ move = false; GetComponent.().Stop(); GetComponent.().Play("idle"); } if(health <= 0){ die(); } if(UIs.health < 0){ UIs.health = 0; // player's health } } function die(){ if(!isdead){ GetComponent.().Play("death"); Destroy(gameObject, 3); isdead = true; move = false; GetComponent.().Stop(); UIs.zombie--; //reducing zombies in UIs script } } function TakenDamage(){ GetComponent.().Play("damage01"); GetComponent.().Stop(); yield WaitForSeconds(GetComponent.().clip.length); hurt = false; move = false; }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



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