Rotating object with onscreen button

I’m using javascript.

I want to rotate a car with an onscreen button.

It’s easy to to create a button, and easy to create a car.

It’s easy to even create a car that if clicked/pushed down will rotate.

What I’m having trouble with, is creating an onscreen button that when pushed down with something like OnMouseButtonDown () will rotate the car.

What I have done is I have a car that the main camera follows. I have a button that moves with the car and is under the car in the hierarchy.

I had two ideas to solve the problem, but I don’t know how to do either.

Is there any way to reference whether or not a button is pushed down in another script?

Is there any way to control another game object with a script from a different object?

If you have any other ideas to solve the problem they would also be appreciated.

You could try adding this if statement in your update method:

if(Input.GetKeyDown("mouse 0"))
    //your rotation script

there is a way to control another game object with a different object’s script
you can do this by declaring the gameobject.
for example:

private GameObject yourobject;

void Awake()
   yourobject = GameObject.Find("yourgameobjectname")

void Update()
       yourobject.transform.position += Vector3.up // consider multiplying by time for smooth movement

please note that the example is written in C# , should work exactly the same in javascript with the correct context.