Question by
Asem AH · Apr 08, 2016 at 07:20 AM ·
transformpositiontransform.position
if transform.position == 5 Change the Scale of game object
pragma strict
var player : GameObject; function Start() { } function Update() {
if (transform.position.x == 5) {
player.transform.localScale.x = 4;
}
if (transform.position.x == -5) {
player.transform.localScale.x = -4;
}
}
i make gameObject and i wanna this game object rotation when its position equeal 5 i use the code above and nothing happen any thing sorry for my english because my age is 13 and my native language is niot english
Comment
Answer by mikelortega · Apr 08, 2016 at 08:02 AM
transform.position.x is a float value, and you should not compare float values with == because you will have precision problems. The same float number might have slightly different representations. Use Equals(float) method instead:
if (transform.position.x.Equals(5.0f))
On the other hand, localScale scales the object but does not rotate.