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
{
}
}
}
Comment
Best Answer
Answer by Quertie · May 01, 2016 at 03:38 PM
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! :)
Your answer
Follow this Question
Related Questions
How to get a vector 3 to vector 2 - c# 1 Answer
Vector3.MoveTowards moving transform 0 Answers
GameObject not looking at me.. 1 Answer
Moving GameObject a specific distance in the Z direction and back again - regardless of rotation 1 Answer
+= operator on transform.localPosition results in random values 1 Answer