Transformを使ってオブジェクトを移動させたとき、座標の値は、とても細かい少数で表示されます。

座標をつかった条件分岐などの場合、こうした誤差のある小数値だと、使い勝手が悪いこともあります。
Positionの値を、整数に変換する方法について、見ていきましょう。
関連記事:
transform.positionの値を小数第2位で端数処理
座標を整数に変換して条件分岐
座標の小数値を端数処理して条件設定
Mathf.Floorを使用する
Cubeオブジェクトを用意し、CubeMove.csを追加しました。

CubeMove.csを記述して、Cubeを動かします。
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | using System.Collections; using System.Collections.Generic; using UnityEngine; public class CubeMove : MonoBehaviour {     private float move = 0.1f;     void Update()     {         Vector3 position = new Vector3(0, 0, move);         transform.Translate(position);         Debug.Log(this.transform.position.z);     } } | 
ゲームプレイして、コンソールを確認します。

position.zの座標が、小数値で表示されています。
これを、Mathf.Floorで整数にかえて取得してみましょう。
もう一度、CubeMove.csを開き、Debug.Logの中に追記します。
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | using System.Collections; using System.Collections.Generic; using UnityEngine; public class CubeMove : MonoBehaviour {     private float move = 0.1f;     void Update()     {         Vector3 position = new Vector3(0, 0, move);         transform.Translate(position);         Debug.Log(Mathf.Floor(this.transform.position.z)); //整数に変換     } } | 
ゲームプレイして、コンソールを確認しましょう。

整数に変換して表示されました。
関連記事:
transform.positionの値を小数第2位で端数処理
座標を整数に変換して条件分岐
座標の小数値を端数処理して条件設定
 
	   
         
         
           
         
           
        