- Home /
Question by
studioglitch · Jul 25, 2017 at 04:15 PM ·
scripting problemspritetopdownspace shooter
My sprites wont change?
Im working on this topdown spaceshooter and i want the rocket to change sprites at certain locations on the x axis. I made this script, and everything works alright except when the x axis is greater than 2 it doesn't switch to RocketRight2
// Update is called once per frame
void Update()
{
position.x += Input.GetAxis("Horizontal") * rocketSpeed * Time.deltaTime;
transform.position = position;
position.x = Mathf.Clamp(position.x, -2.8f, 2.8f);
if (transform.position.x >= 1.8f)
{
RocketRight2S();
}
if (transform.position.x >= 1f)
{
RocketRight1S();
}
if (transform.position.x <= -1f)
{
RocketLeft1S();
}
if (transform.position.x <= -2f)
{
RocketLeft2S();
}
}
void RocketRight2S()
{
GameObject.FindWithTag("Rocket").GetComponent<SpriteRenderer>().sprite = RocketRight2;
}
void RocketRight1S()
{
GameObject.FindWithTag("Rocket").GetComponent<SpriteRenderer>().sprite = RocketRight1;
}
void RocketLeft2S()
{
GameObject.FindWithTag("Rocket").GetComponent<SpriteRenderer>().sprite = RocketLeft2;
}
void RocketLeft1S()
{
GameObject.FindWithTag("Rocket").GetComponent<SpriteRenderer>().sprite = RocketLeft1;
}
Please help I don't know what to do :/
Comment