Hi, I’m making Space shooter game in which I want to place boss. I have script in which I wrote how boss should move and it works but… I know i can do better. Any ideas how can I improve that code?
void FixedUpdate () {
time -= Time.deltaTime;
if(time < 0 && time > -2.7)
{
this.gameObject.GetComponent<Rigidbody2D>().velocity = -1 * this.gameObject.transform.up * speed;
}
else if(time < -2.7 && time > -5)
{
this.gameObject.GetComponent<Rigidbody2D>().velocity = -1 * this.gameObject.transform.up * 0;
}
else if(time < -5 && time > -7.7)
{
this.gameObject.GetComponent<Rigidbody2D>().velocity = -1 * this.gameObject.transform.right * speed;
}
else if (time < -7.7 && time > -9.7)
{
this.gameObject.GetComponent<Rigidbody2D>().velocity = -1 * this.gameObject.transform.up * 0;
}
else if(time < -9.7 && time > -11)
{
this.gameObject.GetComponent<Rigidbody2D>().velocity = this.gameObject.transform.up * 1/speed;
}
else if (time < -11 && time > -11.5)
{
this.gameObject.GetComponent<Rigidbody2D>().velocity = -1 * this.gameObject.transform.up * speed * 10;
}
else if (time < -11.5 && time > -16.15)
{
this.gameObject.GetComponent<Rigidbody2D>().velocity = this.gameObject.transform.up * speed;
}
else if (time < -16.15 && time > -19)
{
this.gameObject.GetComponent<Rigidbody2D>().velocity = -1 * this.gameObject.transform.up * 0;
}
else if (time < -19 && time > -24.5)
{
this.gameObject.GetComponent<Rigidbody2D>().velocity = this.gameObject.transform.right * speed;
}
else if (time < -24.5 && time > -26.5)
{
this.gameObject.GetComponent<Rigidbody2D>().velocity = this.gameObject.transform.up * 0;
}
else if (time < -26.5 && time > -27.8)
{
this.gameObject.GetComponent<Rigidbody2D>().velocity = this.gameObject.transform.up * 1 / speed;
}
else if (time < -27.8 && time > -28.3)
{
this.gameObject.GetComponent<Rigidbody2D>().velocity = -1 * this.gameObject.transform.up * speed * 10;
}
else if (time < -28.3 && time > -33)
{
this.gameObject.GetComponent<Rigidbody2D>().velocity = this.gameObject.transform.up * speed;
}
else if (time < -33 && time > -36)
{
this.gameObject.GetComponent<Rigidbody2D>().velocity = -1 * this.gameObject.transform.up * 0;
}
else if (time < -36 && time > -38.8)
{
this.gameObject.GetComponent<Rigidbody2D>().velocity = -1 * this.gameObject.transform.right * speed;
}
else if (time < -38.8 && time > -41)
{
this.gameObject.GetComponent<Rigidbody2D>().velocity = this.gameObject.transform.up * 0;
}
else if (time < -41 && time > -42.3)
{
this.gameObject.GetComponent<Rigidbody2D>().velocity = -1 * this.gameObject.transform.up * speed;
}
else if (time < -42.3 && time > -70)
{
this.gameObject.GetComponent<Rigidbody2D>().velocity = this.gameObject.transform.up * 0;
Laser();
}
else if (time < -70 && time > -71.2)
{
laserSpawnDelay = 0;
this.gameObject.GetComponent<Rigidbody2D>().velocity = this.gameObject.transform.up * speed;
}
else if (time < -71.2)
{
time = -2.7f;
}
GunShoot();
RocketShoot();
//Laser();
}