示例#1
0
    void Start()
    {
        /* NOTE! We recommend that you limit the maximum frequency between frames.
         * This is because the controllers use Update() and not FixedUpdate(),
         * and yet need to update often enough to respond sufficiently fast.
         * Unity advises to keep this value "between 1/10th and 1/3th of a second."
         * However, even 100 milliseconds could seem slightly sluggish, so you
         * might want to experiment w/ reducing this value even more.
         * Obviously, this should only be relevant in case your framerare is starting
         * to lag. Most of the time, Update() should be called very regularly.
         */

        // If you have changed these names, please replace below "names"

        /*Left = GameObject.Find("LeftWall");
        *  Right = GameObject.Find("RightWall");
        *  Racket = GameObject.Find("Racket");*/
        try {
            Sword       = GameObject.Find("Sword");
            Light       = GameObject.Find("VolumetricLinePrefab");
            Player      = GameObject.Find("player");
            EnemyMaster = GameObject.Find("EnemyMaster");
            Unitychan   = GameObject.Find("unitychan");
            Cube        = GameObject.Find("Cube");
            Enemy0      = GameObject.Find("Enemy0");
            Enemy1      = GameObject.Find("Enemy1");
            Camera      = GameObject.Find("Main Camera");
            text        = GameObject.Find("Text").GetComponent <Text>();
            animator    = Unitychan.GetComponent <Animator>();
            rb          = Unitychan.GetComponent <Rigidbody>();
            opening     = true;
            countdown   = false;
            playing     = false;
            gameover    = false;
            clear       = false;
        } catch (Exception e) {
            Debug.Log("exception");
        }

        Light.SetActive(false);
        Sword.SetActive(false);
        Player.SetActive(false);
        EnemyMaster.SetActive(false);
        Enemy0.SetActive(false);
        Enemy1.SetActive(false);
        Unitychan.SetActive(false);
        Cube.SetActive(false);


        _Style          = new GUIStyle();
        _Style.fontSize = 20;

        Time.maximumDeltaTime = 0.1f;

        int count = UniMoveController.GetNumConnected();

        // Iterate through all connections (USB and Bluetooth)
        for (int i = 0; i < count; i++)
        {
            UniMoveController move = gameObject.AddComponent <UniMoveController>();             // It's a MonoBehaviour, so we can't just call a constructor

            // Remember to initialize!
            if (move.Init(i) == PSMove_Connect_Status.MoveConnect_NoData)
            {
                Destroy(move);                  // If it failed to initialize, destroy and continue on
                continue;
            }

            // This example program only uses Bluetooth-connected controllers
            PSMoveConnectionType conn = move.ConnectionType;
            if (conn == PSMoveConnectionType.Unknown || conn == PSMoveConnectionType.USB)
            {
                Destroy(move);
            }
            else
            {
                _Moves.Add(move);
                move.OnControllerDisconnected += HandleControllerDisconnected;

                // 球体LEDの基本セッティング 赤色
                move.SetLED(Color.red);
            }
        }
        _TimeCount = Time.time;
    }
    // Update is called once per frame
    void Update()
    {
        if (opening)
        {
            Player_scripts.score = 0;
            text.text            = "SELECT LEVEL ○easy ×normal PRESS ANY BUTTON";
            Light.SetActive(false);
            Sword.SetActive(false);
            Player.SetActive(false);
            EnemyMaster.SetActive(false);
            Enemy0.SetActive(false);
            Enemy1.SetActive(false);
            Unitychan.SetActive(true);
            Cube.SetActive(false);

            if (_TimeCount + _Opening_Time < Time.time)
            {
                //rb.velocity = Vector3.zero;
                //animator.SetBool("Stop", true);
                Cube.SetActive(true);
                // ボタンイベント UnityのInput.GetButtonと同じ仕組み
                if (Input.GetKey("up"))
                {
                    _TimeCount = Time.time;
                    opening    = false;
                    countdown  = true;
                    NormalSpeed();
                }
                Debug.Log("Success");
                if (Input.GetKey("down"))
                {
                    _TimeCount = Time.time;
                    opening    = false;
                    countdown  = true;
                    HighSpeed();
                }
            }
            else
            {
                Unitychan.transform.position += transform.forward * 0.035f;
                animator.SetBool("Stop", false);
            }
        }
        if (countdown)
        {
            Light.SetActive(false);
            Sword.SetActive(false);
            Player.SetActive(false);
            EnemyMaster.SetActive(false);
            Enemy0.SetActive(false);
            Enemy1.SetActive(false);
            Unitychan.SetActive(false);
            Cube.SetActive(true);
            if (_TimeCount + _Countdown_Time1 > Time.time)
            {
                text.text = "3";
            }
            else if (_TimeCount + _Countdown_Time2 > Time.time)
            {
                text.text = "2";
            }
            else if (_TimeCount + _Countdown_Time3 > Time.time)
            {
                text.text = "1";
            }
            else
            {
                countdown  = false;
                playing    = true;
                _TimeCount = Time.time;
                Light.SetActive(false);
                Sword.SetActive(true);
                Unitychan.SetActive(false);
                Cube.SetActive(false);
                Player.SetActive(true);
                Player_scripts.Set();
                Enemy0.SetActive(true);
                Enemy0_scripts.Set();
                Enemy1.SetActive(true);
                Enemy1_scripts.Set();
                EnemyMaster.SetActive(true);
                Player_scripts.Move();
                Camera_scripts.Move();
                Light_scripts.Move();
                Sword_scripts.Move();
            }
        }


        if (playing)
        {
            if (Input.GetKey("up"))
            {
                Debug.Log("Circle Down");
                Light.SetActive(true);
                Sword.SetActive(false);
            }
            Debug.Log("Success");
            if (Input.GetKey("down"))
            {
                Debug.Log("Circle UP");
                Light.SetActive(false);
                Sword.SetActive(true);
            }
        }

        if (gameover)
        {
            if (_TimeCount + _Gameover_Time < Time.time)
            {
                ReStart();
                this.gameover = true;
                Light.SetActive(false);
                Sword.SetActive(false);
                Player.SetActive(false);
                EnemyMaster.SetActive(true);
                Enemy0.SetActive(false);
                Enemy1.SetActive(false);
                Unitychan.SetActive(false);
                Cube.SetActive(true);
                text.text = "Score " + Player_scripts.score + "press ○ to ReStart";

                if (Input.GetKey("up"))
                {
                    Opening();
                    _TimeCount = Time.time;
                    UnityChan_scripts.ReStart();
                    Light.SetActive(false);
                    Sword.SetActive(false);
                    Player.SetActive(false);
                    EnemyMaster.SetActive(false);
                    Enemy0.SetActive(false);
                    Enemy1.SetActive(false);
                    Unitychan.SetActive(true);
                    Cube.SetActive(false);
                    Enemy0_scripts.ReStart();
                }
            }
        }
    }
示例#3
0
    void Update()                                  //1フレームが更新されるたび呼び出される関数
    {
        foreach (UniMoveController move in _Moves) //PSMoveが正常的に繋がっている時に実行される
        {
            // Instead of this somewhat kludge-y check, we'd probably want to remove/destroy
            // the now-defunct controller in the disconnected event handler below.
            if (move.Disconnected)
            {
                continue;
            }

            // ボタンイベント UnityのInput.GetButtonと同じ仕組み
            if (move.GetButtonDown(PSMoveButton.Circle) && playing)
            {
                Debug.Log("Circle Down");
                Light.SetActive(true);
                Debug.Log("Circle 1");
                Sword.SetActive(false);
                Debug.Log("Circle 2");
            }
            Debug.Log("Success");
            if (move.GetButtonUp(PSMoveButton.Cross) && playing)
            {
                Debug.Log("Circle UP");
                Light.SetActive(false);
                Sword.SetActive(true);
            }

            // 押すボタンによって球体のLEDの色が変わる
            if (move.GetButtonDown(PSMoveButton.Circle))
            {
                move.SetLED(Color.red);
            }
            else if (move.GetButtonDown(PSMoveButton.Cross))
            {
                move.SetLED(Color.red);
            }
            else if (move.GetButtonDown(PSMoveButton.Square))
            {
                move.SetLED(Color.red);
            }
            else if (move.GetButtonDown(PSMoveButton.Triangle))
            {
                move.SetLED(Color.red);
            }
            else if (move.GetButtonDown(PSMoveButton.Move))
            {
                move.SetLED(Color.black);
            }

            // トリガーボタンが押されたら振動する
            move.SetRumble(move.Trigger);

            // transform.localPosition = move.Position;
            transform.localRotation = move.Orientation;

            // PSMoveの球体の座標によってオブジェクトの座標が変わる

            /*if ((float)PSMoveDetect.Sx > Left.transform.position.x + Racket.transform.localScale.x/2
             *  && (float)PSMoveDetect.Sx < Right.transform.position.x - Racket.transform.localScale.x/2) //ゲーム内ではみ出さないようにオブジェクトの移動範囲を制限
             * {
             *      transform.position = new Vector3(((float)PSMoveDetect.Sx), GetComponent<Rigidbody>().position.y, GetComponent<Rigidbody>().position.z);
             *      Left_touch = false;
             *      Right_touch = false;
             * }
             * else if ((float)PSMoveDetect.Sx <= Left.transform.position.x)
             * {
             *      transform.position = new Vector3(Left.transform.position.x + Racket.transform.localScale.x/2, GetComponent<Rigidbody>().position.y, GetComponent<Rigidbody>().position.z);
             *      Left_touch = true;
             * }
             *
             * else if ((float)PSMoveDetect.Sx >= Right.transform.position.x)
             * {
             *      transform.position = new Vector3(Right.transform.position.x - Racket.transform.localScale.x/2, GetComponent<Rigidbody>().position.y, GetComponent<Rigidbody>().position.z);
             *      Right_touch = true;
             * }*/


            //PSMoveの球体の座標によってオブジェクトに掛かる力量が変わる
            //rigidbody.AddForce(
            //                 transform.Right * Input.GetAxisRaw( "Horizontal" ) * Accel,
            //               ForceMode.Impulse );

            //if( (float)PSMoveDetect.Sx / 3 > 0)
            //	rigidbody.AddForce(transform.Right * ((float)PSMoveDetect.Sx), ForceMode.Impulse );


            if (IsCollided == true)             //関数OnCollisionEnterでIsCollidedの値がtrueに変わった場合
            {
                Timer += Time.deltaTime;        //0から時間を計る
                if (Timer < Collide_time)       //計った時間が0からCollide_time以内の場合
                {
                    move.SetLED(Color.magenta); //LEDの色を赤色にする
                    move.SetRumble(1f);         //1の硬度で振動する
                }
                else //計った時間が15msを超える場合
                {
                    Timer = 0; //タイマーを0に戻す
                    move.SetLED(Color.red);
                    IsCollided = false;
                }
            }

            if (opening)
            {
                Light.SetActive(false);
                Sword.SetActive(false);
                Player.SetActive(false);
                EnemyMaster.SetActive(false);
                Enemy0.SetActive(false);
                Enemy1.SetActive(false);
                Unitychan.SetActive(true);
                Cube.SetActive(false);

                if (_TimeCount + _Opening_Time < Time.time)
                {
                    rb.velocity = Vector3.zero;
                    animator.SetBool("Stop", true);
                    Cube.SetActive(true);
                    // ボタンイベント UnityのInput.GetButtonと同じ仕組み
                    if (move.GetButtonDown(PSMoveButton.Circle))
                    {
                        _TimeCount = Time.time;
                        opening    = false;
                        countdown  = true;
                    }
                    Debug.Log("Success");
                    if (move.GetButtonUp(PSMoveButton.Cross))
                    {
                        _TimeCount = Time.time;
                        opening    = false;
                        countdown  = true;
                    }
                }
                else
                {
                    Unitychan.transform.position += Unitychan.transform.forward * 0.01f;
                }
            }
            if (countdown)
            {
                Light.SetActive(false);
                Sword.SetActive(false);
                Player.SetActive(false);
                EnemyMaster.SetActive(false);
                Enemy0.SetActive(false);
                Enemy1.SetActive(false);
                Unitychan.SetActive(false);
                Cube.SetActive(true);
                if (_TimeCount + _Countdown_Time1 < Time.time)
                {
                    text.text = "1";
                }
                else if (_TimeCount + _Countdown_Time2 < Time.time)
                {
                    text.text = "2";
                }
                else if (_TimeCount + _Countdown_Time3 < Time.time)
                {
                    text.text = "3";
                }
                else
                {
                    countdown  = false;
                    playing    = true;
                    _TimeCount = Time.time;
                }
            }
        }
    }