I am trying to make my first mobile game with unity. In this game, you click an object and it disappears. Here is my code:
using UnityEngine;
using System.Collections;
public class Touch : MonoBehaviour {
public GameObject g;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
UnityEngine.Touch myTouch = Input.GetTouch (0);
if (myTouch.position == g.transform.position)
{
Destroy (g);
}
}
}
however a get an error:
Assets/Scripts/Touch.cs(19,29): error CS0121: The call is ambiguous between the following methods or properties: UnityEngine.Vector3.operator ==(UnityEngine.Vector3, UnityEngine.Vector3)’ and UnityEngine.Vector2.operator ==(UnityEngine.Vector2, UnityEngine.Vector2)'.
What am I doing wrong?
you're trying to compare a
– gjfVector2(touch.position) with aVector3(transform.position) since the components of eachVectoris afloat, you should use something like [Mathf.Approximately()][1] too... [1]: http://docs.unity3d.com/ScriptReference/Mathf.Approximately.html