Simulate a mouse click

I have boxes which are just sprites. When the user clicks on the box it turns a different color. I want to simulate the user click to turn these boxes the different color before the user has a chance to click.

I have this snippet of code so far:

square = UnityEngine.Random.Range (1, 37);
moveSquare = square.ToString();
setup = GameObject.Find (moveSquare);

the names of the boxes are 1,2,3,4,and so on. So all I need is a type function. Any help would be appreciated!

There is no way to fake a Input. While use inputs (Input.GetMouseButtonDown (0)) is easy, in the end, you will never use it directly because this type of situation.

You usually use you own input class that allow you to switch keys and fake inputs.

A very simple example:

class MyInput {
 public bool fakeClick;

 public static IsMouseActionDown()
    return fakeClick || Input.GetMouseButtonDown(0);

If you need to fake a click, simple set fakeClick true, and then in next frame to false.

A more specific solution for your situations is simple a case of change your code into a function that receive all Input params.

public void MoveStuff(bool buttonClicked, int mouseX, int mouseY) { ... }

On update you call with inputs

public void Update() { MoveSuff(Input.GetMouseButtonDown (0), Input,mousePosition.x, Inpnut.mousePosition.y); } 

And when you need to fake it simple call

MyClickLocation.MoveStuff(true, 120, 321)