Question by
GabrielFleury · Sep 24, 2018 at 05:18 AM ·
raycastnavmeshtagsmultiple objects
How do I affect multiple objects in a single click?
When I click on a sheep I need to make it follow the object with the tag "destiny", for this I created a trigger event that upon clicking activates the function in which the sheep goes to the position of the tag. Only when I click on several only one suffers the effect. Tips on other ways to do this?`using UnityEngine; using UnityEngine.AI; [RequireComponent(typeof(NavMeshAgent))] [RequireComponent(typeof(CapsuleCollider))] [RequireComponent(typeof(Rigidbody))] public class Sheep : MonoBehaviour {
public GameObject Player;
//public GameObject casa1;
public static NavMeshAgent navMesh;
public static bool andar = false;
private void Start()
{
Player = GameObject.FindWithTag("destino");
navMesh = GetComponent<NavMeshAgent>();
}
public void follow()
{
if (andar == true)
{
Debug.Log("andar true");
navMesh.destination = Player.transform.position;
/* while (Vector3.Distance(transform.position, Player.transform.position) < 1.5f)
{
navMesh.Stop();
}*/
}
// navMesh.Stop();
}
}`
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612175138im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
error in motion navmesh 0 Answers
Raycast not changing value 0 Answers
AI Raycasting Patrol and Chase,AI enemy raycast help 0 Answers
Raycast not working (NO ERRORS!) 1 Answer
Need help with Ray casting syntax. 1 Answer