Пример #1
0
    void Awake()
    {
        //用于梯子sprite替换
        if (IsTutorial == false)
        {
            _ladderRenderer = LadderUI.GetComponent <SpriteRenderer>();

            Texture2D ladderUp = (Texture2D)Resources.Load("LadderUp");                                //更换为红色主题英雄角色图片
            up = Sprite.Create(ladderUp, _ladderRenderer.sprite.textureRect, new Vector2(0.5f, 0.5f)); //注意居中显示采用0.5f值

            Texture2D ladderDown = (Texture2D)Resources.Load("LadderDown");                            //更换为红色主题英雄角色图片
            down = Sprite.Create(ladderDown, _ladderRenderer.sprite.textureRect,
                                 new Vector2(0.5f, 0.5f));                                             //注意居中显示采用0.5f值


            Tinylytics.AnalyticsManager.LogCustomMetric("GameStart", "0");
        }



        childOutlines = GetComponentsInChildren <cakeslice.Outline>();

        if (IsTutorial == false)

        {
            Outlinecallingleft  = LadderLeft.GetComponent <OutlineCalling>();
            OutlinecallingRight = LadderRight.GetComponent <OutlineCalling>();
        }



        //Get the Rewired Player object for this player and keep it for the duration of the character's lifetime
        RewirePlayer = ReInput.players.GetPlayer(playerId);
        animBaby     = BabyModel.GetComponent <Animator>();
        // Set up references.
        anim        = GetComponent <Animator> ();
        _myCollider = GetComponent <Collider>();
        bodyTran    = this.gameObject.transform.GetChild(0);

        playerRb      = GetComponent <Rigidbody>();
        originalScale = transform.localScale;
        rd            = GetComponent <MeshRenderer>();
        _audioSource  = GetComponents <AudioSource>();
        //spotLight = transform.Find("SpotLight").gameObject;
    }
Пример #2
0
    void LadderControl()
    {
        RaycastHit hit;

        Debug.DrawRay(transform.position + Vector3.up, transform.forward * 2f, Color.yellow);


        if (IsLeft == true)
        {
            BottomLocator   = LeftBottomLocator;
            UpperLocator    = LeftUpperLocator;
            BottomAngle     = 45;
            UpperAngle      = 45;
            _outlineCalling = Outlinecallingleft;
        }
        else
        {
            BottomLocator   = RightBottomLocator;
            UpperLocator    = RightUpperLocator;
            BottomAngle     = -45;
            UpperAngle      = -45;
            _outlineCalling = OutlinecallingRight;
        }


        if (Physics.Raycast(transform.position + Vector3.up, transform.forward * 2f, out hit, 2f))
        {
            if (hit.collider.CompareTag("DownStairs"))
            {
                aroundLadder           = true;
                _ladderRenderer.sprite = up;
                //为了避免collider直接被teleport到目标位置
                if (temp == false)
                {
                    LadderUI.SetActive(true);
                    temp = true;
                    outlineEnabled();
                }

                //_outlineCalling.playerOnLadder = true;
                PlayerOnLadder();

                if (RewirePlayer.GetButtonDown("Interact"))
                {
                    transform.position    = BottomLocator.transform.position;
                    transform.rotation    = Quaternion.AngleAxis(BottomAngle, Vector3.up);
                    _myCollider.isTrigger = true;
                    //anim.SetTrigger("Reset");
                    anim.SetBool("Jump", true);
                    PlayerEnabled = false;
                    LadderUI.SetActive(false);
                }
            }
            else if (hit.collider.CompareTag("UpStairs"))
            {
                aroundLadder           = true;
                _ladderRenderer.sprite = down;


                //为了避免collider直接被teleport到目标位置
                if (temp == false)
                {
                    LadderUI.SetActive(true);
                    temp = true;
                    outlineEnabled();
                }

                //_outlineCalling.playerOnLadder = true;
                outlineEnabled();

                PlayerOnLadder();

                if (RewirePlayer.GetButtonDown("Interact"))
                {
                    transform.position = UpperLocator.transform.position;
                    //print("hittttttLadder");
                    transform.rotation    = Quaternion.AngleAxis(UpperAngle, Vector3.up);
                    _myCollider.isTrigger = true;
                    //anim.SetTrigger("Reset");
                    anim.SetBool("Fall", true);

                    PlayerEnabled = false;
                    LadderUI.SetActive(false);
                }
            }
            else
            {
                LadderUI.SetActive(false);
                aroundLadder = false;
                //PlayerEnabled = true;

                _outlineCalling.player1 = false;
                _outlineCalling.player2 = false;
                _outlineCalling.player3 = false;
            }
        }
        else
        {
            LadderUI.SetActive(false);
            //PlayerEnabled = true;
        }


        AnimatorStateInfo stateinfo = anim.GetCurrentAnimatorStateInfo(0);

        //transform.position = _myAnim.rootPosition;


        if (stateinfo.IsName("Jump") && (stateinfo.normalizedTime > 1.0f))
        {
            _myCollider.isTrigger = false;
            if (anim.GetBool("Jump"))
            {
                transform.position             = UpperLocator.transform.position;
                _myCollider.transform.position = UpperLocator.transform.position;

                outlineEnabled();
                PlayerOnLadder();


                anim.SetBool("Jump", false);
                PlayerEnabled = true;
            }
        }


        else if (stateinfo.IsName("Fall") && (stateinfo.normalizedTime > 1.0f))
        {
            _myCollider.isTrigger = false;
            if (anim.GetBool("Fall"))
            {
                transform.position             = BottomLocator.transform.position;
                _myCollider.transform.position = BottomLocator.transform.position;

                PlayerEnabled = true;
                outlineEnabled();
                PlayerOnLadder();

                anim.SetBool("Fall", false);
                PlayerEnabled = true;
            }
        }
    }