- Home /
Question by
Theonardo23 · Dec 13, 2018 at 06:46 AM ·
positiontransform.position
transform.position return the wrong value
A little background on what I'm working on : Basically I have a cube model which will be used to generate some terrain structure. All of those gameobjects were created on Runtime by doing :
float yPos = 0f;
float scale = 0.5f;
var robot = GameObject.Instantiate(grassTile) as GameObject;
robot.transform.position = new Vector3(0, yPos, 0);
robot.transform.localScale = new Vector3(scale, scale, scale);
robot.transform.rotation = Quaternion.Euler(-90, 0, 0);
width = robot.GetComponent<Renderer>().bounds.size.z;
for(int i=0;i<5;i++){
yPos += width;
robot = GameObject.Instantiate(grassTile) as GameObject;
robot.transform.position = new Vector3(0, yPos, 0);
robot.transform.localScale = new Vector3(scale, scale, scale);
robot.transform.rotation = Quaternion.Euler(-90, 0, 0);
//attach the script
robot.AddComponent<CubeBehavior>();
}
What's inside the CubeBehavior.cs :
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.touchCount > 0) {
Debug.Log(transform.position);
}
}
What happened is no matter which cube I touch, it will always return the last cube position. Please enlighten me about this problems. Thanks in advance
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612183906im_/https://answers.unity.com/themes/thub/images/avi.jpg)