Cube.transform.position.x

Hello to all,

I try to move my cube by 30 pixels on the x and 45 pixels on the z (when you click on the cube three times).

A simple example with :

    int i;
    public GameObject Cube;

    void OnMouseDown() {

        i = ++1;

        if (i == 3) {


            Cube.transform.position.x = 30;
            Cube.transform.position.y = 45;

       //or Cube.transform.position = Vector2(30, 45);

        }
    }

I tried to change the x and z positions,
or I tried to introduce a Vector2.

The problem is that the compiler sends me each time an error message.

Your help is welcome,

A+

Not sure but maybe try assigning a int to i (sorry if it is wrong as i am just starting to learn c#)

Cela ne change rien, la variable est déclarée en int en haut du code.

Merci quand même,

A+

Cube.transform.position = new Vector3 (30, 0, 45);

The position vector must be replaced as a whole. You cannot assign individual components.