Skip to main content

010. Unity3d Tutorial - Targetting Enemies 3/3

See video

This part 3/3 of our 5th tutorial in creating a small hack and slash game using the Unity Game Engine. This wee we look at how to set up a basic targeting system that will allow us to cycle through enemy mobs until we have the one we want targeted.

Tags:

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Offline
Joined: Mar 20 2011

Super Tutorial! :)

Offline
Joined: Jul 21 2011

I still didn't understand that pair of code:

public void SortTargetsByDistance(){
targets.Sort(delegate(Transform t1, Transform t2) { return Vector3.Distance(t1.position, myTransform.position).CompareTo(Vector3.Distance(t2.position, myTransform.position)); } );
}

Why we used delegate and we didn't used t1 and t2 variables another part but this function. Why we used ComparedTo? What did we compared? Thanks for answers...

Offline
Joined: Mar 23 2012

i think it compares the distances between the different cubes to the player.

Offline
Joined: Dec 3 2011

pa.target = selectedTarget.gameObject;

small letter of first character for "gameObject"

Offline
Joined: Mar 20 2012

i´m not sure if i did something wrong, but... it seems to work only with 3 or more targets?! can´t use tab to switch targets if there are just 2 targets. weird.