x


Select an Enemy C#

Is it possible to use a RayCast (idk know what a raycast is) to select an enemy? Like if i have a variable lets say

public Transform EnemySelected;

And i wanted it if you clicked a object that had the script NPC_AI.cs that this variable would equal that enemy? If it is possible how could i go upon doing this?

EDIT:

Sorry i forgot to include this i have a tag also set up if its an enemy

more ▼

asked Jul 23 '11 at 04:30 AM

BrennanVargas1 gravatar image

BrennanVargas1
14 10 10 15

Retagged...

Don't forget, you need to put a comma in between each tag

Jul 23 '11 at 05:26 AM AVividLight

alright sorry i forgot about that

Jul 23 '11 at 05:33 AM BrennanVargas1
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

For a good intro video to raycasting, click here

Also, the Unity documentation is your friend.

You can get the transform of an object that was hit with your raycast.. http://unity3d.com/support/documentation/ScriptReference/RaycastHit-transform.html

More information on raycasts can be found here http://unity3d.com/support/documentation/ScriptReference/Physics.Raycast.html

more ▼

answered Jul 23 '11 at 05:42 AM

Meltdown gravatar image

Meltdown
5.6k 18 25 49

(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

By RSS:

Answers

Answers and Comments

Topics:

x4166
x1531
x322
x19

asked: Jul 23 '11 at 04:30 AM

Seen: 1651 times

Last Updated: Jul 23 '11 at 05:42 AM