mohammad mohammad - 7 months ago 35
C# Question

Unity 5.4 find the length of the object

hi every one i am using Unity 5.4.1f1 to create a simple game , i want my code to add platforms which is a piece of the street at the end of the first platform , with out hard coding the street length which is 14 m

so i tried this code :

i added in start :

lastPos = platForm.transform.position;
size = platForm.transform.localScale.z;

and added called this code in update :

Vector3 currentPos = lastPos;

currentPos.z +=size;
lastPos =currentPos;

but it did't work it always get the size 1 even if it is 14
so is that doable in unity or i should do it hard coded ?

enter image description here


You can use renderer.bounds

For example

var size  = GetComponent<Renderer>().bounds.size;