Operator '==' is ambiguous on operands of type 'Vector2' and 'Vector3'

Can I have some help on how to fix this issue thanks. I’ve tried setting ‘cube’ to a Vector 2 but that didn’t work.

using UnityEngine;
using System.Collections;

public class CubeScript : MonoBehaviour {

    public GameObject cube;

    Touch userTouch = Input.GetTouch(0);

    // Use this for initialization
	void Start () {
        cube = GameObject.Find("Cube");
	}
	
	// Update is called once per frame
	void Update () {
        cube.transform.position = new Vector2(cube.transform.position.x, cube.transform.position.y);
        if (userTouch.position == cube.transform.position) //this line underlined red
        {

        }
	
	}
}

what you could try doing is this:

Forget about this line:

cube.transform.position = new Vector2(cube.transform.position.x, cube.transform.position.y); // Don't need to do this!

and just change the if statement:

if (userTouch.position == new Vector2(cube.transform.position.x, cube.transform.position.y))
{
    ...
}

I hope this works! :slight_smile: