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)'

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 Vector2 (touch.position) with a Vector3 (transform.position) since the components of each Vector is a float, you should use something like [Mathf.Approximately()][1] too... [1]: http://docs.unity3d.com/ScriptReference/Mathf.Approximately.html

1 Answer

1

you’re trying to compare a Vector2 (touch.position) with a Vector3 (transform.position)

since the components of each Vector is a float, you should use something like Mathf.Approximately() too…

And the reason it gives the error it does, is that the Vector2 and Vector3 classes (strangely, IMO) can be implicitly cast to one another. So rather than just telling you you can't compare them, it's failing to determine whether you want to compare them as Vector2's or as Vector3's.

Mathf.Floor should be enough. Then (A - B) >= limitValue.

You have 2 options: 1. connect your Unity server with WWW class to a webserver using your favorite stack 2. use mysql in Unity directly: https://www.youtube.com/watch?v=kcKtGCDeFDg (it's in french but code is visible)