Quantcast
Channel: Questions in topic: "follow"
Viewing all articles
Browse latest Browse all 536

Hi i need help, how to make the player attack the next enemy with the same tag one by one until all is destroyed,How to destroy all the objects with the same tag one by one until no one is left

$
0
0
The problem with this script is after killing its first victim it does not search anymore another enemy with the same tag, i need help for my player to search and destroy the remaining enemies with the same tag killing one by one until no remaining enemy is left, thank you.. #pragma strict /* THIS IS THE MAIN SCRIPT TO CONTROL AI BEHAVIOR AND AUTO SHOOT ENEMY WHEN IN RANGE AND AUTO NAVIGATE AND FIND ENEMY WHEN OUT OF RANGE */ //var TargetToFollowPosition : Transform; var FollowSpeed : float ; private var mySwitch : boolean; private var shootSwitch : boolean; private var targetToFollow : Transform; private var numSwitch : float; private var bulletShotSound : AudioSource; var projectile : Rigidbody; var BulletSpeed : float; var BulletInterval :float; var Spawnpoint : Transform; private var TimeContainer : float; function Start () { bulletShotSound = gameObject.GetComponent.(); targetToFollow = GameObject.FindGameObjectWithTag("Enemy").transform; numSwitch = 0; //mySwitch = false; shootSwitch = false; //speed = 3; } ///// COLLISION DETECTOR WHEN ENEMY IS IN RANGE function OnTriggerStay(col : Collider) { if(col.gameObject.CompareTag("Enemy")) { // mySwitch = true; shootSwitch = true; numSwitch = 1; } } //////// DETECTION WHEN NOT IN RANGE function OnTriggerExit(col : Collider) { if(col.gameObject.CompareTag("Enemy")) { // mySwitch = false; shootSwitch = false; numSwitch = 0; } } function Update () { ////// UPDATE //////////// TimeContainer += Time.deltaTime; ///////// ENABLE FIRING if(shootSwitch == true) { if(TimeContainer >= BulletInterval) { bulletShotSound.Play(); //var clone : Rigidbody; var clone = Instantiate(projectile, Spawnpoint.position, projectile.rotation); clone.velocity = Spawnpoint.TransformDirection (Vector3.forward*BulletSpeed); Destroy(clone,1.0f); TimeContainer = 0; } } ////// FOLLOW ENEMY WHILE NOT IN RANGE if(numSwitch == 0) { transform.LookAt(targetToFollow); transform.position += transform.forward * FollowSpeed * Time.deltaTime; } } ////// UPDATE ///////////,The problem here is, the player will stop looking other enemy objects after it kills its first victim, i need a script that will enable the player to seek and destroy all the remaining enemies, thanks #pragma strict /* THIS IS THE MAIN SCRIPT TO CONTROL AI BEHAVIOR AND AUTO SHOOT ENEMY WHEN IN RANGE AND AUTO NAVIGATE AND FIND ENEMY WHEN OUT OF RANGE */ //var TargetToFollowPosition : Transform; var FollowSpeed : float ; private var mySwitch : boolean; private var shootSwitch : boolean; private var targetToFollow : Transform; private var numSwitch : float; private var bulletShotSound : AudioSource; var projectile : Rigidbody; var BulletSpeed : float; var BulletInterval :float; var Spawnpoint : Transform; private var TimeContainer : float; function Start () { bulletShotSound = gameObject.GetComponent.(); targetToFollow = GameObject.FindGameObjectWithTag("Enemy").transform; numSwitch = 0; //mySwitch = false; shootSwitch = false; //speed = 3; } ///// COLLISION DETECTOR WHEN ENEMY IS IN RANGE function OnTriggerStay(col : Collider) { if(col.gameObject.CompareTag("Enemy")) { // mySwitch = true; shootSwitch = true; numSwitch = 1; } } //////// DETECTION WHEN NOT IN RANGE function OnTriggerExit(col : Collider) { if(col.gameObject.CompareTag("Enemy")) { // mySwitch = false; shootSwitch = false; numSwitch = 0; } } function Update () { ////// UPDATE //////////// TimeContainer += Time.deltaTime; ///////// ENABLE FIRING if(shootSwitch == true) { if(TimeContainer >= BulletInterval) { bulletShotSound.Play(); //var clone : Rigidbody; var clone = Instantiate(projectile, Spawnpoint.position, projectile.rotation); clone.velocity = Spawnpoint.TransformDirection (Vector3.forward*BulletSpeed); Destroy(clone,1.0f); TimeContainer = 0; } } ////// FOLLOW ENEMY WHILE NOT IN RANGE if(numSwitch == 0) { transform.LookAt(targetToFollow); transform.position += transform.forward * FollowSpeed * Time.deltaTime; } } ////// UPDATE ///////////

Viewing all articles
Browse latest Browse all 536

Trending Articles



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