I went through your code and fixed a couple of things,
I removed something that you need to put back (only because i don’t have the whole code, so for instance the first if statement, and the CanSubtract which is now a simple Debug (just put back your own code).
Although i don’t really understand what you’re trying to do, here’s the code that worked and let me know if you need anything else, Distance is successfully changing and the if tests are working.
Thanks for voting up and accepting as “Answered”.
using UnityEngine;
using System.Collections;
public class HasMoved : MonoBehaviour {
public GameObject [] Cubes;
float Distance;
void Start(){
Debug.Log( "Coordinates: {" + transform.position.x + ", " + transform.position.y + "}");
Cubes = GameObject.FindGameObjectsWithTag ("Cube");
Distance = Mathf.Infinity;
}
void Update(){
foreach (GameObject CubeTag in Cubes)
{
if (Vector3.Distance (transform.position, CubeTag.transform.position) < Distance)
{
Distance = Vector3.Distance (transform.position, CubeTag.transform.position);
}
if (Distance <= 5)
{
Debug.Log("Can Subtract True");
}
else
{
Debug.Log("Can Subtract False");
}
}
Debug.Log (Distance);
}
}