Example #1
0
    // Update is called once per frame
    void Update()
    {
        if (isShoot == false)
        {
            timer += Time.deltaTime;
            if (timer >= shootTimeInterval)
            {
                isShoot = true;
                timer  -= shootTimeInterval;
            }
        }
        if (Input.GetKeyDown(KeyCode.W) || playerController.Top)
        {
            isTopKeyDown = true;
        }
        if (Input.GetKeyUp(KeyCode.W) || !playerController.Top)
        {
            isTopKeyDown = false;
        }
        if (Input.GetKeyDown(KeyCode.S) || playerController.Down)
        {
            isBottomDown = true;
        }
        if (Input.GetKeyUp(KeyCode.S) || !playerController.Down)
        {
            isBottomDown = false;
        }

        if (playerController.Projectile)
        {
            playerJump.Shoot(rigidbody.velocity.x, isTopKeyDown, isBottomDown);
        }

        if (isShoot && isToShoot && (isProjectile || Input.GetKeyDown(KeyCode.J)))
        {
            //进行射击的操作
            audio.Play();
            switch (playerController.state)
            {
            //case PlayerState.PlayerJump:
            //  playerJump.Shoot(rigidbody.velocity.x, isTopKeyDown, isBottomDown);
            //    break;
            case PlayerState.PlayerGround:
                playerGround.Shoot(rigidbody.velocity.x, playerController.Top, playerController.Down);
                break;

            case PlayerState.PlayerDown:

                playerDown.Shoot(rigidbody.velocity.x, playerController.Top, playerController.Down);
                break;

            default:
                break;
            }
            isProjectile = false;
            isToShoot    = false;
        }
    }
Example #2
0
    private void Update()
    {
        if (canShoot == false)
        {
            timer += Time.deltaTime;
            if (timer >= shootTimerInterval)
            {
                canShoot = true;
                timer   -= shootTimerInterval;
            }
        }

        if (Input.GetKeyDown(KeyCode.W))
        {
            isTopKeyDown = true;
        }
        if (Input.GetKeyUp(KeyCode.W))
        {
            isTopKeyDown = true;
        }
        if (Input.GetKeyDown(KeyCode.S))
        {
            isBottomKeyDown = true;
        }
        if (Input.GetKeyUp(KeyCode.S))
        {
            isBottomKeyDown = false;
        }
        if (canShoot && Input.GetKeyDown(KeyCode.J))
        {
            //gameObject.GetComponent<AudioSource>().Play();
            switch (playerMove.state)
            {
            case PlayerState.PlayerGround:
                playerGround.Shoot(rigidBody.velocity.x, isTopKeyDown, isBottomKeyDown);
                break;

            case PlayerState.PlayerJump:
                playerJump.Shoot(rigidBody.velocity.x, isTopKeyDown, isBottomKeyDown);
                break;

            case PlayerState.PlayerDown:
                playerDown.Shoot(rigidBody.velocity.x, isTopKeyDown, isBottomKeyDown);
                break;
            }
        }
    }
Example #3
0
    // Update is called once per frame
    void Update()
    {
        bool isAtk = false;

        if (playMove.isShooting && Time.time > shootTime + shootInterval)
        {
            isShooting = true;
            Ray        ray1 = new Ray(gameObject.transform.position, Vector3.right);
            RaycastHit hit1;
            if (Physics.Raycast(ray1, out hit1, 1f))
            {
                if (hit1.transform.gameObject.name == "Enemy1(Clone)")
                {
                    isAtk = true;
                    hit1.transform.gameObject.GetComponent <Enemy1>().state = Enemy1.EnemyState.DEAD;
                }
                if (hit1.transform.gameObject.name == "Enemy2(Clone)")
                {
                    isAtk = true;
                    hit1.transform.gameObject.GetComponent <Enemy2>().state = Enemy2.EnemyState.DEAD;
                }
            }
            Ray        ray2 = new Ray(gameObject.transform.position, Vector3.left);
            RaycastHit hit2;
            if (Physics.Raycast(ray2, out hit2, 1f))
            {
                if (hit2.transform.gameObject.name == "Enemy1(Clone)")
                {
                    isAtk = true;
                    hit2.transform.gameObject.GetComponent <Enemy1>().state = Enemy1.EnemyState.DEAD;
                }
                if (hit2.transform.gameObject.name == "Enemy2(Clone)")
                {
                    isAtk = true;
                    hit2.transform.gameObject.GetComponent <Enemy2>().state = Enemy2.EnemyState.DEAD;
                }
            }
            if (!isAtk)
            {
                switch (playMove.status)
                {
                case PlayerMove.PlayerStatus.GROUND:
                    playGround.Shoot();
                    break;

                case PlayerMove.PlayerStatus.DOWN:
                    playDown.Shoot();
                    break;

                case PlayerMove.PlayerStatus.JUMP:
                    playJump.Shoot();
                    break;

                default:
                    break;
                }
            }
            else
            {
                switch (playMove.status)
                {
                case PlayerMove.PlayerStatus.GROUND:
                    playGround.isShoot    = true;
                    playGround.bodyStatus = BodyStatus.Hor_Atk;
                    break;

                case PlayerMove.PlayerStatus.DOWN:
                    playDown.isShoot    = true;
                    playDown.bodyStatus = BodyStatus.Hor_Atk;
                    playDown.legStatus  = LegStatus.DownShoot;
                    break;

                case PlayerMove.PlayerStatus.JUMP:
                    playJump.isShoot    = true;
                    playJump.bodyStatus = BodyStatus.Hor_Atk;
                    break;

                default:
                    break;
                }
            }
            shootTime = Time.time;
        }
        else
        {
            //btnShootPressed = false;
        }
        if (playMove.isThrowing && Time.time > throwTime + throwInterval && !playMove.btnUpPressed)
        {
            switch (playMove.status)
            {
            case PlayerMove.PlayerStatus.GROUND:
                playGround.Throw();
                break;

            case PlayerMove.PlayerStatus.DOWN:
                playDown.Throw();
                break;

            case PlayerMove.PlayerStatus.JUMP:
                playJump.Throw();
                break;

            default:
                break;
            }
            throwTime = Time.time;
        }
        else
        {
        }
    }