Quantcast
Channel: Questions in topic: "loops"
Viewing all articles
Browse latest Browse all 184

Piece of code including foreach loop not working correctly

$
0
0
Everytime I press play, "Distance" is always 0… What am I doing wrong? if (DataValue == CubeManagerGet.GetComponent ().CurrentCube) { TextGet.text = "Coordinates: {" + transform.position.x + ", " + transform.position.y + "}"; Debug.Log ("YES"); GameObject [] Cubes = GameObject.FindGameObjectsWithTag ("Cube"); float Distance = Mathf.Infinity; 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) { CanSubtract = true; } else { CanSubtract = false; } } Debug.Log (Distance); }

Viewing all articles
Browse latest Browse all 184

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>