if transform.position == 5 Change the Scale of game object

Updated on April 8, 2016 in [A] Unity Scripting
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
4 on April 8, 2016

#pragma strict
var player : GameObject;
function Start()
{
}
function Update() {
if (player.transform.position.x == 5) {
player.transform.localScale.x = 4;
}
if (player.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

what the wrong of my code
sorry for my english

  • Liked by
Reply
1 on April 8, 2016

I dont fully understand but I guess you want to flip a sprite depending on the direction the player is moving in…

In that case, try setting the scale to 1 and -1 instead of 4.

on April 8, 2016

thank you for this comment . i try this but it is nothing happen.
so it is wrong

Show more replies
  • Liked by
Reply
Cancel
1 on April 8, 2016

The problem is that the Sprite is probably never going to be exactly 5… Try using >= 5 or =< -5

on April 8, 2016

it is not work thank you for this comment

Show more replies
  • Liked by
Reply
Cancel