示例#1
0
    void OnTriggerExit2D(Collider2D other)
    {
        SpeedUpOnOil speedUpObj = other.gameObject.GetComponent <SpeedUpOnOil>();

        if (speedUpObj == null)
        {
            return;
        }
        if ((speedUp.value & (1 << other.gameObject.layer)) != 0)
        {
            speedUpObj.exitOil();
        }
    }
示例#2
0
        /// <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();
            }
        }
示例#3
0
    void OnTriggerEnter2D(Collider2D other)
    {
        DispearAtReset dispearAtReset;

        if ((dispearAtReset = other.GetComponent <DispearAtReset>()) != null)
        {
            dispearAtReset.dispear();
        }
        //Debug.Log("enter oil");
        SpeedUpOnOil speedUpObj = other.gameObject.GetComponent <SpeedUpOnOil>();

        if (speedUpObj == null)
        {
            return;
        }
        if ((speedUp.value & (1 << other.gameObject.layer)) != 0)
        {
            speedUpObj.enterOil();
        }
    }
示例#4
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();
        }