Hello friends I am new with Unity and wondering if there are alternatives to ray casting. My game is a road traffic manager and when the players taps a car I want it to stop. This is my code for the movement. I tried the getmousebuttondown function but realized that every gameobject with this script attached would just stop or go depending on when they spawn. Thank you in advance for your helpful advice
public float SPEED;
public Transform[] FirstPossition;
int StopPossition;
public bool GO = false;
void Para()
{
if (Input.GetMouseButtonDown (0))
{
GO = !GO;
if (GO)
{
SPEED = 5;
} else {
SPEED = 0;
}
//GO = false;
}
}
void Start () {
StopPossition = 0;
}
void Update()
{
if (transform.position == FirstPossition [StopPossition].transform.position)
{
StopPossition+=Random.Range(0,4);
}
transform.position = Vector3.MoveTowards (transform.position, FirstPossition [StopPossition].position, SPEED * Time.deltaTime);
if (StopPossition >= 5)
{
StopPossition = 0;
}
Para ();
Debug.Log (StopPossition);
}