コード例 #1
0
ファイル: Pankapu.cs プロジェクト: GitHubforXiaoming/Demo
        /// <summary>
        /// Control the player move horizontally when the state is "Running State", "Crouching State" or "Swimming State".
        /// </summary>
        public void MoveHorizontally()
        {
            float moveFactor = 1;

            //
            if (StateMachine.CurrentState == PlayerRunState.Instance || StateMachine.CurrentState == PlayerJumpState.Instance)
            {
                moveFactor = 1;
            }
            else if (StateMachine.CurrentState == PlayerSwinState.Instance)
            {
                moveFactor = config.swimSpeed / config.walkSpeed;
            }

            if (InputManager.LeftBtnDown)
            {
                speedOfX = -config.walkSpeed * moveFactor;
            }
            else if (InputManager.RightBtnDown)
            {
                speedOfX = config.walkSpeed * moveFactor;
            }
            else
            {
                speedOfX = 0;
            }
            SpeedUpOnOil speedUpOnOil = GetComponent <SpeedUpOnOil>();

            if (speedUpOnOil != null && speedUpOnOil.isOnOil())
            {
                Debug.Log("speed up");
                speedOfX *= speedUpOnOil.speedupRate;
            }



            rigid.velocity = new Vector2(speedOfX, rigid.velocity.y);
            //rigid.MovePosition(new Vector2(rigid.position.x + Time.deltaTime * speedOfX, rigid.position.y));

            if (speedOfX > 0 && isFacingRight == false)
            {
                HorizontalFlip();
            }
            else if (speedOfX < 0 && isFacingRight == true)
            {
                HorizontalFlip();
            }
        }
コード例 #2
0
        // Update is called once per frame
        void FixedUpdate()
        {
            if (!isDead)
            {
                SpeedUpOnOil speedUpOnOil = GetComponent <SpeedUpOnOil>();
                float        speedOfX     = speed;
                if (speedUpOnOil != null && speedUpOnOil.isOnOil())
                {
                    Debug.Log("speed up");
                    speedOfX *= speedUpOnOil.speedupRate;
                }
                anRigidbody.velocity = new Vector2(speedOfX, anRigidbody.velocity.y);
            }
            else
            {
                anRigidbody.velocity = new Vector2(0, anRigidbody.velocity.y);
            }
            lastPositionX = transform.position.x;

            CheckDroppedIceCube();

            if (isDead)
            {
                EventCenter.Braodcast(EventType.AnDeath);
                timer += Time.deltaTime;
                if (timer > 2.10f)
                {
                    isDead = false;
                    EventCenter.Braodcast(EventType.AnRespawn);
                    Respawn();
                    timer = 0;
                }
            }

            CheckMove();
        }