Code optimization

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();

    }

First of all you can create a bool that will check automaticall everything for you and instead of this

        if (time < 0 && time > -2.7)
        {
            this.gameObject.GetComponent<Rigidbody2D>().velocity = -1 * this.gameObject.transform.up * speed;
        }

You will have this

        if (NameYourBool(0f, -2.7f))
        {
            this.gameObject.GetComponent<Rigidbody2D>().velocity = -1 * this.gameObject.transform.up * speed;
        }

Also it is not necessary to create the samy copy and paste scripts with a little bit different values. You can just create a void that will do all of the copy and paste work for you.

    void YourName(Vector3 RightPart)
    {
        gameObject.GetComponent<Rigidbody2D>().velocity = RightPart;
    }

And after this your piece of code will look a lot cleaner

        if (NameYourBool(0f, -2.7f))
        {
            YourName(-1 * this.gameObject.transform.up * speed);
        }

Reply to me if you will get any results or if you have some questions.

If your code is aimed at making an object follow a preset path, then look into the Unity Animator. Alternatively, perhaps an easier to read version of your code would be something like:

Update(){
		
            // avoid uisng "time" as a variable because it is too close to a system function name 
		time_counter -= Time.deltaTime;	
							
            // use this to hold the movement we are about to make
		Vector3 movement;	

            // use these to remove repetitive text									
		Vector3 up=this.gameObject.transform.up;
		Vector3 right = this.gameObject.transform.right;

		if (checkTime (-2.7f, 0f)) {
			movement = -1 * up * speed;
		}

		if (checkTime (-5f, -2.7f)) {
			movement = Vector3.zero;
		}

		if (checkTime (-7f, -5f)) {
			movement = -1*right*speed;
		}

		// etc
	
		this.gameObject.GetComponent<Rigidbody> ().velocity = movement;

	
	}

	// this function returns true if the time variable is between lower and upper limts
	bool checkTime(float lowerTime, float upperTime){
		
		if (time_counter >= lowerTime && time_counter < upperTime) {
			return true;
		} else {
			return false;
		}
	}

A couple of other things:
**Best to avoid “time” as a variable, as “Time” (Capital T) is a system function.

**You were testing for “>” and “<” which then leaves no solution for “=”. So the checkTime function tests “>=” to make sure it’s covered.

**There were a couple of places where you made some math for velocity and then multiplied by 0 (so whatever the math, the result would be 0). The quick route to that is Vector3.Zero.