// We marked this a s"Fixed"Update because we
    // are using it to mess with physics
    void FixedUpdate()
    {
        // Add a forward force
        rb.AddForce(0, 0, forwardForce * Time.deltaTime);

        if (Input.GetKey("d"))
        {
            // Only executed if condition is met
            //rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
            Command moveR  = new MoveRight(rb, sidewaysForce);
            Invoker invoke = new Invoker();
            invoke.SetCommand(moveR);
            invoke.ExeCommand();
            commandLog.text += moveR.ToString() + "\n";
        }

        if (Input.GetKey("a"))
        {
            // Only executed if condition is met
            //rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
            Command moveL  = new MoveLeft(rb, sidewaysForce);
            Invoker invoke = new Invoker();
            invoke.SetCommand(moveL);
            invoke.ExeCommand();
            commandLog.text += moveL.ToString() + "\n";
        }

        if (rb.position.x < -8f || rb.position.x > 8f)
        {
            FindObjectOfType <gameManager>().endGame();
        }
    }
    void FixedUpdate()
    {
        rb.AddForce(0, 0, forwardForce * Time.deltaTime);

        if (Input.GetKey("d"))
        {
            Command moveRight = new MoveRight(rb, sideForce);
            Invoker invoker   = new Invoker();
            invoker.SetCommand(moveRight);
            commandsUI.text += "\n" + moveRight.ToString();
            invoker.ExecuteCommand();
        }

        if (Input.GetKey("a"))
        {
            Command moveLeft = new MoveLeft(rb, sideForce);
            Invoker invoker  = new Invoker();
            invoker.SetCommand(moveLeft);
            commandsUI.text += "\n" + moveLeft.ToString();
            invoker.ExecuteCommand();
        }

        if (rb.position.y < -1f)
        {
            FindObjectOfType <GameManager>().EndGame(null);
        }

        if (rb.GetComponentInParent <Transform>().position.z > milestoneScore)
        {
            OnMilestone?.Invoke();
        }
    }
Exemplo n.º 3
0
    void FixedUpdate()
    {
        //this is a standtard push that scales diretly to frame rate
        //Time.deltaTime negates the frame rate diffirences and the really high number helps the cube to actually move

        rb.AddForce(0, 0, forwardSpeed * Time.deltaTime);


        if (Input.GetKey("d"))
        {
            Command _moveRight = new MoveRight(rb, lateralSpeed);
            Invoker invoker    = new Invoker();
            invoker.SetCommand(_moveRight);

            invoker.ExecuteComand();
            commandDisplay.text += "\n" + _moveRight.ToString();
        }

        if (Input.GetKey("a"))
        {
            Command _moveLeft = new MoveLeft(rb, lateralSpeed);
            Invoker invoker   = new Invoker();
            invoker.SetCommand(_moveLeft);
            commandDisplay.text += "\n" + _moveLeft.ToString();
            invoker.ExecuteComand();
        }

        if (Input.GetKey("w"))
        {
            Command _moveUp = new MoveUp(rb, lateralSpeed);
            Invoker invoker = new Invoker();
            invoker.SetCommand(_moveUp);
            commandDisplay.text += "\n" + _moveUp.ToString();
            invoker.ExecuteComand();
        }

        if (Input.GetKey("s"))
        {
            //loacal _moveDown  //calling the command in commmand
            Command _moveDown = new MoveDown(rb, lateralSpeed);
            Invoker invoker   = new Invoker();
            invoker.SetCommand(_moveDown);
            commandDisplay.text += "\n" + _moveDown.ToString();
            invoker.ExecuteComand();
        }

        if (rb.position.y < -1f)
        {
            FindObjectOfType <GameManager>().EndGame();
        }
    }