- Home /
Random location when clicked on
Assume I have a character that is game ready with animations. I am wondering how to make this character walk to random locations when clicked on. Locations predetermined by markers.
Example: You have a room with "markers" in each corner. Every time the character is clicked on he will walk to one of four corners inside the room at random.
Any ideas ?
Answer by betaFlux · Sep 10, 2014 at 09:19 PM
May be something like this:
GameObject[] markers;
void Start()
{
markers = GameObject.FindGameObjectsWithTag("marker");
//requires you to tag every marker as "marker"
}
void OnMouseDown() // Requires a collider on your character
{
//if you use NavMesh
GetComponent<NavMeshAgent>().destination = markers[Random.Range(0, markers.Length)].transform.position;
}
Of course it depends on which character movement system you use.
Hey man, thanks for the reply I'm gonna try and see how far that gets me any start is a good start!
Your answer
Follow this Question
Related Questions
how to add a walking animation when character is moving? 3 Answers
random animations 2 Answers
Making Character Stand? 1 Answer
How to play transitioned animation at random time 1 Answer
Animate character sitting in a chair 1 Answer