コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        if (health.isDead)
        {
            return;
        }

        //transform.forward = moveDirection;

        Ray   cameraRay   = mainCamera.ScreenPointToRay(Input.mousePosition);
        Plane groundPlane = new Plane(Vector3.up, Vector3.zero);
        float rayLength;

        if (groundPlane.Raycast(cameraRay, out rayLength))
        {
            pointToLook = cameraRay.GetPoint(rayLength);
            Debug.DrawLine(cameraRay.origin, pointToLook, Color.blue);

            transform.LookAt(new Vector3(pointToLook.x, transform.position.y, pointToLook.z));
        }

        //Add Everything to state machine to get the game to run and play better

        /*switch (curPlayerState)
         * {
         *  case PlayerStateMachine.Walk:
         *      PlayerMove();
         *      break;
         *  case PlayerStateMachine.Attack:
         *      PlayerAttack();
         *      break;
         *  case PlayerStateMachine.Magic:
         *      PlayerMagic();
         *      break;
         *  case PlayerStateMachine.Idle:
         *      PlayerIdle();
         *      break;
         * }*/

        if (Input.GetButtonDown("Fire1"))
        {
            isAttacking = true;
            GetComponentInChildren <SwordMechanic>().Swing(true);
        }
        else
        {
            GetComponentInChildren <SwordMechanic>().Swing(false);
            isAttacking = false;
        }

        if (Input.GetButton("Fire2") && !isAttacking)
        {
            //use dot product to see if the enemy is in front of player to block damage
            //this would allow the player to still take damage from behind or to the player's side

            shield.SetActive(true);
            moveDirection = Vector3.zero;
            foreach (SwordMechanic swords in enemySword)
            {
                swords.damage = blockDamage;
            }
        }
        else
        {
            shield.SetActive(false);
            moveDirection = new Vector3(horizontalInput, (gravity * -1 * Time.deltaTime), VerticalInput);
            foreach (SwordMechanic swords in enemySword)
            {
                swords.damage = swords.origDamage;
            }
        }

        if (Input.GetKeyDown(KeyCode.E) && !isAttacking)
        {
            magicWeapon.Shoot();
        }


        horizontalInput = Input.GetAxis("Horizontal");
        VerticalInput   = Input.GetAxis("Vertical");


        moveDirection *= playerSpeed;

        if (moveDirection != Vector3.zero)
        {
            prevDirection = moveDirection;
        }


        if (Input.GetButtonDown("Jump"))
        {
            Debug.Log("Trying to dash");
            moveDirection *= dashDistance;
        }

        //Debug.Log("The player's current state is " + curPlayerState);


        playerController.Move(moveDirection * Time.deltaTime);
    }