Is it possible to convert an integer to a Vector3?
using UnityEngine;
using System.Collections;
public class grasstestdelete : MonoBehaviour {
// Use this for initialization
void Start () {
//Debug.Log(Mathf.RoundToInt(10.7F));
}
// Update is called once per frame
void Update () {
transform.position = Mathf.RoundToInt (gameObject.transform.position.x);
//transform.position = Mathf.RoundToInt (gameObject.transform.position.y);
//transform.position = Mathf.RoundToInt (gameObject.transform.position.z);
}
}
2 Answers
2
well if you wanted to do this right, you would have to get a copy of the Vector3, change the vectors and pass it back.
using your code and modifying:
using UnityEngine;
using System.Collections;
public class grasstestdelete : MonoBehaviour {
// Use this for initialization
void Start () {
//Debug.Log(Mathf.RoundToInt(10.7F));
}
// Update is called once per frame
void Update () {
Vector3 pos = transform.position; // get a copy
pos.x = Mathf.RoundToInt(gameObject.transform.position.x);
pos.y = Mathf.RoundToInt(gameObject.transform.position.y);
pos.z = Mathf.RoundToInt(gameObject.transform.position.z);
transform.position = pos; // now put it back and override the vector3 with the new one.
}
}
Umm, no… A Vector 3 contains 3 floating point values. In your code, that Vector3 represents a position in 3 dimensional space. How would you represent that with a single int value? Could the number 23, say, represent a position in 3d space?
Thank you!
– Derpyness