Question by
ventiv · Feb 10, 2017 at 07:07 PM ·
c#localscale
how to check the value of localScale.x? [2D]
so I'm creating a 2d Enemy for my game and I'm trying to change the localScale based on if the localScale is already a certain value but I can't figure out how to check the current localScale.x in an if statement.
void flipEnemy()
{
if(player.transform.position.x < transform.position.x && player.transform.localScale.x == 1)
{
transform.localScale = new Vector2(transform.localScale.x * -1, transform.localScale.y);
}
if(player.transform.position.x > transform.position.x)
{
if(transform.localScale.x < transform.localScale.x * -1)
{
transform.localScale = new Vector2(transform.localScale.x * 1, transform.localScale.y);
}
}
}
Comment
the second if about the scale checks the scale multiplied with -1. but if that's -1 due to the first you check for 1, which it is not. you can use $$anonymous$$athf.Sign ins$$anonymous$$d which returns the current sign
Your answer