- Home /
Target = NetworkedMe
How can I make my Enemy script AI "target" equal to the local player, so that it doesnt goes haywire looking for all of those other players. For now my script looks for the Player tag gameObject, and since in multiplayer the players are all set as Player tag. So how do i make the enemy follow local player? heres the looking for target line of code of the script:
target = GameObject.FindWithTag("Player").transform;
i would just make custom tags for each player that joins and update the player tags every time someone leaves or enters the match; assu$$anonymous$$g you will only have a certain amount of people in your matches
Answer by whydoidoit · May 15, 2013 at 11:53 PM
Add a script to the local player that isn't on the instantiated network players which uses a singleton to identify it:
LocalPlayer.cs
public class LocalPlayer : MonoBehaviour
{
public static Transform instance;
void Awake()
{
if(instance == null)
instance = transform;
}
void OnDestroy()
{
if(instance == transform)
instance = null;
}
}
Then find the local player by doing:
LocalPlayer.instance
Your answer
Follow this Question
Related Questions
Assigning Player Numbers 0 Answers
Identifying local player issue 0 Answers
Unity networking tutorial? 6 Answers
Deleting a player over the network 1 Answer
How to get LocalPlayer position in Photon Bootcamp Demo? 1 Answer