// Use this for initialization void Start () { controller = gameObject.AddComponent<UniMoveController>(); if(!controller.Init(playerIndex)) { Debug.Log ("Could not initialize controller "+playerIndex); } controller.InitOrientation(); controller.ResetOrientation(); controller.SetLED(playerColor); }
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. */ Time.maximumDeltaTime = 0.1f; int count = UniMoveController.GetNumConnected(); Debug.Log("count = " + count); if (count == 0) { noMovesText.text = "No moves connected!"; } else if (count == 1) { noMovesText.text = "Only 1 move connected!"; } else { noMovesText.enabled = false; // 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)) { 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.InitOrientation(); move.ResetOrientation(); if (i == 0) { move.SetLED(Color.magenta); // <F> player 1 } else { move.SetLED(Color.cyan); // <F> player 2 } players[i].GetComponent <Spaceship>().Move = move; players[i].GetComponent <Spaceship>().AlternativeStart(); } } } }
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. */ Time.maximumDeltaTime = 0.1f; moveControllerPrefab = GameObject.Find("MoveController"); Destroy(moveControllerPrefab); if (moveControllerPrefab == null || moveControllerPrefab.GetComponent <MoveController>() == null) { Debug.LogError("GameObject with object named \"MoveController\" with script MoveController is missing from the scene"); } 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)) { 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; move.InitOrientation(); move.ResetOrientation(); // Start all controllers with a white LED move.SetLED(Color.white); // adding the MoveController Objects on screen GameObject moveController = GameObject.Instantiate(moveControllerPrefab, Vector3.right * count * 2 + Vector3.left * i * 4, Quaternion.identity) as GameObject; MoveController moveObj = moveController.GetComponent <MoveController>(); moveObjs.Add(moveObj); moveObj.SetLED(Color.white); } } }
// Update is called once per frame void Update() { if (phase == Phase.Connecting) { bool allConnected = true; for (int i = 0; i < nodes.Count; i++) { if (UniMoveController.GetNumConnected() > 0) { if (nodes[i].controller == null) { UniMoveController controller = nodes[i].gameObject.AddComponent <UniMoveController>(); if (controller.Init(i)) { controller.InitOrientation(); controller.ResetOrientation(); nodes[i].Init(controller, this.debugButtons[i]); } else { Destroy(controller); allConnected = false; } } } else { nodes[i].InitDebug(i <= 1?1:2, this.debugButtons[i]); } } if (allConnected) { for (int i = 0; i < nodes.Count; i++) { if (nodes[i].type == 1) { Target target = nodes[i].gameObject.AddComponent <Target>(); target.HitEvent += OnTargetHit; targets.Add(target); } else { Attacker attacker = nodes[i].gameObject.AddComponent <Attacker>(); attacker.HitEvent += OnAttackerHit; attacker.TimeoutEvent += OnAttackerTimeout; attacker.TimeoutWarningEvent += OnAttackerTimeoutWarning; attackers.Add(attacker); } } phase = Phase.Waiting; } } else if (phase == Phase.Waiting) { // start game if (Input.GetKeyDown(KeyCode.Space)) { bool practice = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift); StartGame(practice); } } else if (phase == Phase.Playing) { // stop game if (Input.GetKeyDown(KeyCode.Space)) { StopGame(); } // heal if (Input.GetKeyDown(KeyCode.H)) { Heal(); } } else if (phase == Phase.Ended) { } if (Input.GetKeyDown(KeyCode.D)) { //ControllerDebug.Active = !ControllerDebug.Active; debugPanel.SetActive(!debugPanel.activeSelf); } if (Input.GetKeyDown(KeyCode.S)) { setupPanel.SetActive(!setupPanel.activeSelf); } }