I have two spheres and I want to give them each different locations to move to…no matter how I assign the location01 value, both of my objects move towards it. I plan on creating many objects throughout my game and want to be able to command each object separately to different locations.
// This creates a destination by right clicking the mouse.
if (Input.GetMouseButtonDown(1))
{
RaycastHit hit;
if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, Mathf.Infinity))
{
location01 = hit.point;
}
}
// This moves the objects toward location01.
transform.position = Vector3.MoveTowards(transform.position, location01, speed * Time.deltaTime);