Ok, after getting my cube to move to another cubes position i have ran into another problem. This problem is that when the cube reaches its destination, the other cube should be deleted, but it isn’t!!:
CODE:
if (GameObject.Find("movePosBlock(Clone)") == null)
{
Vector3 g = new Vector3(Mathf.Round(hit.point.x), Mathf.Ceil(hit.point.y), Mathf.Round(hit.point.z));
if (Input.GetMouseButtonDown(1))
{
Instantiate(movePosBlock, g, Quaternion.identity);
iTween.MoveTo(stuartCharacter, g, 5);
}
if (stuartCharacter.transform.position.Equals(g)) {
Destroy(GameObject.Find("movePosBlock(Clone)"));
Debug.Log("Deleted Waypoint!");
}
}
Of course it doesn’t. Floating point numbers don’t compare well, especially if you round one of them before comparison. You should be checking the distance between the position and g, not that they are the same. (and don’t round them). If 1 unit = 1 meter, and 1 centimeter is close enough, you would get the vector between the two positions, and check that the length is < 0.01.
edit: (vector1 - vector2).magnitude will give you the distance.