Beispiel #1
0
    void Update()
    {
        // Input Handling
        if (Input.GetButtonDown("Jump"))
        {
            jump = true;
        }
        else if (Input.GetButtonUp("Jump"))
        {
            jump = false;
        }
        horizontal = Input.GetAxis("Horizontal");
        vertical   = Input.GetAxis("Vertical");
        sprint     = Input.GetButton("Sprint");

        if (horizontal != 0 || vertical < 0)
        {
            sprint = false;
        }

        // Movement Control
        CollisionFlags flag = controller.collisionFlags;

        if (controller.isGrounded)
        {
            moveDirection  = new Vector3(horizontal, 0, vertical);
            moveDirection  = transform.TransformDirection(moveDirection);
            moveDirection *= sprint ? 1.5f * SPEED : SPEED;

            if (jump)
            {
                moveDirection.y = JUMP_FORCE;

                if ((flag & CollisionFlags.Sides) == CollisionFlags.Sides)
                {
                    moveDirection.x = moveDirection.z = 0;
                }
            }
        }

        moveDirection.y += gravity * MASS * Time.deltaTime;

        controller.Move(moveDirection * Time.deltaTime);

        if (transform.position.y < -5)
        {
            pc.ChangeHealth(-100);
            enabled = false;
        }
    }
 public void EndWave()
 {
     if (curWave == maxWaves)
     {
         Victory();
     }
     else
     {
         builder.enabled = true;
         builder.UpdateResources(creditsWave * curWave, basesWave * curWave);
         curWave++;
     }
     wave.text = "Wave " + curWave + "/" + maxWaves;
     pc.ChangeAmmo(150);
     pc.ChangeHealth(100);
 }