- Home /
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
Retagged...
Don't forget, you need to put a comma in between each tag
Answer by Meltdown · Jul 23, 2011 at 05:42 AM
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
Your answer
![](https://koobas.hobune.stream/wayback/20220612153546im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
C# Raycast Prefab script activation 1 Answer
How to get distance between two object by using a pinpoint? Or Tag? 1 Answer
Multiple Cars not working 1 Answer