If anybody can help me it would be greatly appreciated. I am trying to set up the turret from the FPS tutorial to kill multiple enemies and it is not working. Originally it was set to attack the fps with the (player) tag. But I added a new tag (enemies), which seem to work only for one gameobject that is with that tag. I would like it to kill all gameoject with that tag. any info or suggestion will be helpful
and I did change the FindWithTag(Player) to (“Enemies”)
function Start () { if (target == null GameObject.FindWithTag(“Enemies”)) target = GameObject.FindWithTag(“Enemies”).transform; still did not work
do I need to add this to my script that i am already using are create another script and attach it to the object with the collider (trigger) here the script that i am using thank u for your reply (i am new to programming).
var attackRange = 30.0;
var shootAngleDistance = 10.0;
var target : Transform;
function Start () {
if (target == null GameObject.FindWithTag(“Enemies”))
target = GameObject.FindWithTag(“Enemies”).transform;
}
function Update () {
if (target == null)
return;
if (!CanSeeTarget ())
return;
// Rotate towards target
var targetPoint = target.position;
var targetRotation = Quaternion.LookRotation (targetPoint - transform.position,
// If we are almost rotated towards target - fire one clip of ammo
var forward = transform.TransformDirection(Vector3.forward);
var targetDir = target.position - transform.position;
if (Vector3.Angle(forward, targetDir) < shootAngleDistance)
SendMessage(“Fire”);
}
function CanSeeTarget () : boolean
{
if (Vector3.Distance(transform.position, target.position) > attackRange)
return false;
var hit : RaycastHit;
if (Physics.Linecast (transform.position, target.position, hit))
return hit.transform == target;
Your problem is you only set a target on start… So it targets the first available object with your tag. Once it’s dead… No more target. You need to have it search for a new target everytime it doesn’t have a target if you want it to attack more then 1 thing… If that makes sense. Pretty much if target = null… Redo what’s in your start function, or come up with a different target detection system.