Exemple #1
0
    void Update()
    {
        if (state == 0)
        {
            //第一次摁下鼠标左键就将最初为零的标志位加1,只有标志位为1时棍子才能旋转
            if (Input.GetKeyDown(KeyCode.Mouse0))
            {
                StickLock++;
            }
            if (Input.GetKey(KeyCode.Mouse0) && StickLock == 1)
            {
                Stick.transform.localScale += new Vector3(0, Velocity * Time.deltaTime, 0);
            }
            //伸长棍子后,延迟0.4秒再进行旋转
            if (Input.GetKeyUp(KeyCode.Mouse0) && StickLock == 1)
            {
                Invoke("StickWait", 0.4f);
            }

            if (StickRotateSwitch == true)
            {
                Stick.transform.Rotate(0, 0, -4.5f);
                angle += 4.5f;
                if (angle == 90)
                {
                    Invoke("CheckStickHitGround", 0.4f);
                    //如果已经旋转90度,则停止旋转
                    StickRotateSwitch = false;
                    if (GroundSwitch == false)
                    {
                        MusicManager.PlayStickFail();
                    }
                }
            }
        }
        if (state == 1)
        {
            PlayAnimation();
            //MoveTowards()是将第一个参数的坐标移动到第二个参数坐标位置,
            Player.transform.position = Vector3.MoveTowards(Player.transform.position, Pos1 + new Vector3(0, 1.167f, 0), 2 * Time.deltaTime);
            if (Player.transform.position == Pos1 + new Vector3(0, 1.167f, 0))
            {
                MusicManager.PlayAddScore();
                MoveStick();
            }
        }
        if (state == -1)
        {
            //float StickLong = Stick.transform.localScale.y + GroundX/2;
            PlayAnimation();
            //这里的位移代码并不是完成移动后再执行下一行,而是刚开始移动就会执行下一行
            //Player.transform.position = Vector3.MoveTowards(Player.transform.position, OriPos + new Vector3(StickLong, 0, 0), 2 * Time.deltaTime);
            //float DesX = OriPos.x + StickLong;
            Player.transform.position = Vector3.MoveTowards(Player.transform.position, StickTopPoint + new Vector3(0.1f, 0.2f, 0), 2 * Time.deltaTime);
            if (Player.transform.position.x >= StickTopPoint.x)
            {
                PlayerRigidbody.useGravity = true;
                Eyes.transform.parent      = null;
            }

            if (Player.transform.position.y < -2)
            {
                PlayerDead();
            }
        }
    }
Exemple #2
0
    void Update()
    {
        if (state == 0)
        {
            //
            if (Input.GetKeyDown(KeyCode.Mouse0))
            {
                StickLock++;
            }
            if (Input.GetKey(KeyCode.Mouse0) && StickLock == 1)
            {
                Stick.transform.localScale += new Vector3(0, Velocity * Time.deltaTime, 0);
            }
            //
            if (Input.GetKeyUp(KeyCode.Mouse0) && StickLock == 1)
            {
                Invoke("StickWait", 0.4f);
            }

            if (StickRotateSwitch == true)
            {
                Stick.transform.Rotate(0, 0, -4.5f);
                angle += 4.5f;
                if (angle == 90)
                {
                    Invoke("CheckStickHitGround", 0.4f);
                    //如果已经旋转90度,则停止旋转
                    StickRotateSwitch = false;
                    if (GroundSwitch == false)
                    {
                        MusicManager.PlayStickFail();
                    }
                }
            }
        }
        if (state == 1)
        {
            PlayAnimation();
            //Move
            Player.transform.position = Vector3.MoveTowards(Player.transform.position, Pos1 + new Vector3(0, 1.167f, 0), 2 * Time.deltaTime);
            if (Player.transform.position == Pos1 + new Vector3(0, 1.167f, 0))
            {
                MusicManager.PlayAddScore();
                MoveStick();
            }
        }
        if (state == -1)
        {
            //float StickLong = Stick.transform.localScale.y + GroundX/2;
            PlayAnimation();
            //Stop moving
            //Player.transform.position = Vector3.MoveTowards(Player.transform.position, OriPos + new Vector3(StickLong, 0, 0), 2 * Time.deltaTime);
            //float DesX = OriPos.x + StickLong;
            Player.transform.position = Vector3.MoveTowards(Player.transform.position, StickTopPoint + new Vector3(0.1f, 0.2f, 0), 2 * Time.deltaTime);
            if (Player.transform.position.x >= StickTopPoint.x)
            {
                PlayerRigidbody.useGravity = true;
                Eyes.transform.parent      = null;
                //BGL.transform.parent = null;
            }

            if (Player.transform.position.y < -2)
            {
                PlayerDead();
            }
        }
    }