var LookAtTarget : Transform;

currently in my game im using

var LookAtTarget : Transform;

to set a target for my turrets which works fine untill its killed the gameobject

could someone please show me how to set the target as a tag, iv tried

var LookAtTarget: GameObject[] = GameObject.FindGameObjectsWithTag("Waypoint");

which then gives me an error message saying “position” is not part of gameobject

could someone please help me >.<

thanks in advance

First thought:

var LookAtTarget: GameObject[];

function Awake() {
    LookAtTarget = GameObject.FindGameObjectsWithTag("Waypoint");
}

Uhhh, I’m guessing from the error message somewhere you’re doing something like:

LookAtTarget[0].position

where it should be:

LookAtTarget[0].transform.position

Or maybe you’re mixing the types:
var LookAtTarget : Transform;
var taggedGameObjects: GameObject[ ] = GameObject.FindGameObjectsWithTag(“Waypoint”);
if (taggedGameObjects.Length > 0)
{
LookAtTarget = taggedGameObjects[0].transform;
}

laurie - thanks, iv tried implementing that into the script but cant get it right, im probably trying to add it in the wrong place, heres where iv put it:

function Update () 
{

		if (LookAtTarget = GameObject.FindGameObjectsWithTag("Waypoint");
	{	
		var rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position);

thanks FizixMan - i think its only because im trying to use .position with gameObject

am i doing something wrong? >.<

Yeah, it’s gameObject.transform.position.

Also check your “if” block, I think you want:
LookAtTarget = GameObject.FindGameObjectsWithTag(“Waypoint”);
if (LookAtTarget != null)
{
//do stuff
}

Why do you have an if statement? try this.

function Start(){
LookAtTarget = GameObject.FindGameObjectsWithTag("Waypoint");
}
]function Update () 
{
		var rotate = Quaternion.LookRotation(LookAtTarget.transform.position - transform.position);
}

FizixMan - when i did

 function Update () 
{
	LookAtTarget = GameObject.FindGameObjectsWithTag("Waypoint");
	if (LookAtTarget != null)
	{

i got this error message

Astrauk - i got the same message as i did with FizixMan

Use “FindWithTag” instead, it will find one object instead of all objects:

var waypointObject : GameObject = GameObject.FindWithTag("Waypoint");
if (waypointObject != null)
{
	LookAtTarget = waypointObject.transform;
	var rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position);
}

ok thanks, heres what iv done

var waypoint : GameObject = GameObject.FindWithTag ("Waypoint");
var damp = 6.0;
var bulletPrefab: Transform;
var savedTime = 0;

function Update () 
{

	if (waypoint != null)
	
	{	
		LookAtTarget = waypoint.transform;
		var rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position);

but i get this error message

I don’t think you can call FindWithTag as part of the initialization. I think you need to split the two:

var waypoint : GameObject;

function Start()
{
	waypoint = GameObject.FindWithTag("Waypoint");
}

heres what iv done

(this is the full code)

 var waypoint : GameObject;
var damp = 6.0;
var bulletPrefab: Transform;
var savedTime = 0;

function Start ()
{
		waypoint = GameObject.FindWithTag("Enemy");
}

function Update () 
{

	if (waypoint)
	{	
		var rotate = Quaternion.LookRotation(waypoint.position - transform.position);
		
		transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);
		
		var seconds : int = Time.time;
		var oddeven = (seconds % 2);
		
		if (oddeven)
		{		
			Shoot(seconds);
		}
	}
}

function Shoot(seconds)
{
	if (seconds!=savedTime)
	{
	
	var bullet = Instantiate(bulletPrefab, transform.Find("turret_sp").transform.position, Quaternion.identity);
	
	bullet.rigidbody.AddForce(transform.forward * 1000);
	
	savedTime = seconds;
}
}

which then tells me .position is not a part of GameObject

but GameObject.tranform is a member of position…so change the relevant things from GameObject to GameObject.transform.
waypoint.position → waypoint.transform.position this should work
…well, it´s the tornado twins tutorial, right?^^ but why you trying to shoot at waypoints? what are you trying to do? well, you also could check your range for your enemies using a raycast or a trigger. a raycast is much cooler, because your turret shouldn´t look throught walls like superman;) and it´s cooler bcause why should a turret at the end of the level knows that you are coming along to destroy it? …but both could activate your turrets. if you´re out of range they will deactivate themself and have got no target…so you don´t need to check for an object with tag “xyz” all the time and you won´t get any error messages, because if there´s no object hitting the range of your turrets with tag “xyz”, they won´t get activated and won´t check for the tag;)
i hope i don´t miss the topic :smile:

ahaa awesome =P thanks

lol, yep >.<

works great but now iv got a new problem,

the turrets shoot one enemy then stops

it doesn’t change targets when the enemy has been destroyed

any ideas? >.<

Never mind, sorted it :slight_smile:

thanks all for your help