Super Tutorial! :)
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.
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...
i think it compares the distances between the different cubes to the player.
pa.target = selectedTarget.gameObject;
small letter of first character for "gameObject"
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.






