I have two characters"agent" moving them on terrain by mouse. My script for both of them is...
public Vector3 point_;
public float mark;
public float mark;
public UI_Button _active_character; // butoon select script
void Update
{
Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit mousePoint;
if (Input.GetMouseButtonUp(0))
{
if (Physics.Raycast(mouseRay, out mousePoint, 100) )
{
point_ = mousePoint.point;
mAgent.SetDestination(mousePoint.point);
mark = Vector3.Distance(point_, gameObject.transform.position);
}
}
}
Here script for character buttons. Every character has it own button.
public bool character1, character2;
void Start()
{
character1 = true;
}
void Update()
{
if (character1 == true)
{
character2 = false;
}
if (character2 == true)
{
character1 = false;
}
if (character1 == fale && character2 == false)
{
// Later. free cam moving...
}
}
public void avatar1_click() // button
{
character1 = !character1;
character2 = false;
}
public void avatar2_click() // button
{
character2 = !character2;
character1 = false;
}
It's possible to control both of them separately by one script by click on button to chose character ?