So i have a basic top down space shooter type of game and i want to change the sprite of the rocket ship regarding to its x axis i have prepared this script but it doesnt work.
void SpriteChange()
{
if(position.x <= 2f)
{
this.GetComponent<SpriteRenderer>().sprite = RocketRight1;
}
if (position.x <= 2)
{
this.GetComponent<SpriteRenderer>().sprite = RocketRight2;
}
if (position.x >= -1)
{
this.GetComponent<SpriteRenderer>().sprite = RocketLeft1;
}
if (position.x >= -1)
{
this.GetComponent<SpriteRenderer>().sprite = RocketLeft2;
}
}
Please help im lost