Before updating to Windows 10 you may need to return your Pro license. More information here

Any ideas on a simple AI script that doesn't use any drag/drop variables

So I have a spawn script that uses instantiate to spawn an enemy prefab. However the AI script on the enemy uses the position of the player within the hierarchy and instantiated prefabs do not keep these variables. does anybody have any advice on how to create an ai script that doesn't use this but still moves towards the player?

more ▼

asked Jan 31, 2012 at 01:54 PM

avatar image

1 31 920 29

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

If your player object has a tag, you can use


to get the first found object with that tag. If you are using the "Player" tag, and make sure that there is only ever one object with it, it should work fine.

more ▼

answered Jan 31, 2012 at 01:56 PM

avatar image

19.4k 24 46 157

Thanks alot, so you think like

var player : GameObject; var playerPosition : Vector3;

function Update (){

player = GameObject.FindWithTag(Player); playerPosition = player.transform.position;


Jan 31, 2012 at 05:00 PM simonheartscake

This worked great. Thanks

Jan 31, 2012 at 06:06 PM simonheartscake
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Jan 31, 2012 at 01:54 PM

Seen: 1009 times

Last Updated: Jan 31, 2012 at 06:06 PM