/// <summary> /// Move the clone. /// </summary> /// <param name="i"> ID of the joystic that is going to move this player. </param> /// <param name="controller"> CharacterController of clone. </param> public void MoveClone(ref int i, GameObject clone) { if (clone != null) { CharacterController controllerClone = clone.GetComponent <CharacterController>(); if (usingKeyboard) { movementClone = new Vector3(Input.GetAxis("Horizontal"), 0f, Input.GetAxis("Vertical")); //Setando movimentação } else { movementClone = new Vector3(UNInput.GetAxis(i, "Right Stick Horizontal"), 0f, UNInput.GetAxis(i, "Right Stick Vertical")); //Setando movimentação } if (movementClone.magnitude < 0.2f) //Se a movementação for pequena(correção do analógico) { movementClone = Vector3.zero; //Zerando movimentação } else { clone.transform.rotation = Quaternion.identity * Quaternion.LookRotation(movementClone, Vector3.up); //Atualizando a rotação } gravity += Vector3.down * forceGravity * Time.deltaTime; //Adicionando a gravidade controllerClone.Move(((clone.transform.rotation * Vector3.forward * currentSpeed) * movementClone.magnitude * Time.deltaTime) + (gravity * Time.deltaTime)); //Movimentando if (gravity.y < -forceGravity) //Se a gravidade for maior que a força gravitacional { gravity = Vector3.down * forceGravity; //Setando o valor máximo da gravidade } } // else // GetComponent<PlayerPickup>().usingClone = false; }
void Axes(int id, Gamepad game) { //Values game.l3X = UNInput.GetAxis(id, AxisCode.LSH); game.l3Y = UNInput.GetAxis(id, AxisCode.LSV); game.r3X = UNInput.GetAxis(id, AxisCode.RSH); game.r3Y = UNInput.GetAxis(id, AxisCode.RSV); game.l2_ = UNInput.GetAxis(id, AxisCode.LT); game.r2_ = UNInput.GetAxis(id, AxisCode.RT); //Left Stick if (game.l3X != 0 || game.l3Y != 0) { game.l3Stick.transform.localPosition = new Vector3(game.l3X * 25f, game.l3Y * 25f, 0f); } else { game.l3Stick.transform.localPosition = Vector3.zero; } //Right Stick if (game.r3X != 0 || game.r3Y != 0) { game.r3Stick.GetComponent <RectTransform>().localPosition = new Vector3(game.r3X * 25f, game.r3Y * 25f, 0f); } else { game.r3Stick.GetComponent <RectTransform>().localPosition = Vector3.zero; } //Left Trigger if (game.l2_ != 0) { game.l2GO.transform.localPosition = new Vector3(game.l2GO.transform.localPosition.x, 220f + (-game.l2_ * 45f), 0f); game.l2GO.GetComponent <Image>().color = game.l2; } else { game.l2GO.transform.localPosition = new Vector3(game.l2GO.transform.localPosition.x, 220f, 0f); game.l2GO.GetComponent <Image>().color = Color.white; } //Right Trigger if (game.r2_ != 0) { game.r2GO.GetComponent <RectTransform>().localPosition = new Vector3(game.r2GO.transform.localPosition.x, 220f + (game.r2_ * -45f), 0f); game.r2GO.GetComponent <Image>().color = game.r2; } else { game.r2GO.GetComponent <RectTransform>().localPosition = new Vector3(game.r2GO.transform.localPosition.x, 220f, 0f); game.r2GO.GetComponent <Image>().color = Color.white; } //Texts game.l3XText.text = "H: " + game.l3X.ToString("F1"); game.l3YText.text = "V: " + game.l3Y.ToString("F1"); game.r3XText.text = "H: " + game.r3X.ToString("F1"); game.r3YText.text = "V: " + game.r3Y.ToString("F1"); game.l2Text.text = game.l2_.ToString("F1"); game.r2Text.text = game.r2_.ToString("F1"); }
public void Update() { if (!eventSystem.enabled) { if (UNInput.GetButtonDown(ButtonCode.B)) { CreditsToMenu(); eventSystem.enabled = true; } } }
protected override void Update() { base.Update(); m_MovementInputValue = (m_MovementInputValue == 0) ? UNInput.GetAxis(m_PlayerNumber, _networkVerticalAxis) : m_MovementInputValue; m_TurnInputValue = (m_TurnInputValue == 0) ? UNInput.GetAxis(m_PlayerNumber, _networkHorizontalAxis) : m_TurnInputValue; if (Input.GetButtonDown(_placeAmpButton) || UNInput.GetButtonDown(m_PlayerNumber, "Action")) { Debug.LogFormat("Player {0} placed an Amp!", m_PlayerNumber); PlaceAmp(); } if (Input.GetKeyDown(KeyCode.Backspace) || UNInput.GetButtonDown(m_PlayerNumber, "Start")) { for (int i = _amps.Count - 1; i >= 0; i--) { var a = _amps[i]; DestroyAmp(a); } _amps.Clear(); } var enemyAmps = GameController.Instance.EnemyAmps(_player); AmpController target = null; var minDist = float.MaxValue; foreach (var a in enemyAmps) { Vector3 point; var dist = a.PowLine.SqrDistanceFromPoint(_transform.position, out point); if (dist < MaxCutSqrDistance && dist < minDist) { minDist = dist; Debug.DrawLine(point, point + Vector3.up * 100f, Color.yellow); target = a; } } if (target != null && Input.GetButton(_cutButton) || UNInput.GetButton(m_PlayerNumber, "Back")) { target.Owner.DestroyAmp(target); } }
void Update() { if (useKeyboard) { tempH = Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow) ? 1 : Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow) ? -1 : 0; tempV = Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow) ? 1 : Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow) ? -1 : 0; action = Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.X); } else { tempH = UNInput.GetAxis(joystickId, AxisCode.LSH); tempV = UNInput.GetAxis(joystickId, AxisCode.LSV); action = UNInput.GetButtonDown(joystickId, ButtonCode.A) || UNInput.GetButtonDown(joystickId, ButtonCode.RightBumper); } if (Mathf.Abs(tempH) > controlRate) { if (tempH > 0) { movement.ChangeDirection(Direction.Right); } else { movement.ChangeDirection(Direction.Left); } } else if (Mathf.Abs(tempV) > controlRate) { if (tempV > 0) { movement.ChangeDirection(Direction.Top); } else { movement.ChangeDirection(Direction.Bottom); } } if (action) { elementBending.Action(); } }
private void DropBlock() { if (catchBlock && guide) { guide.Throw(); } if (!catchBlock && guide) { guide.Clear(); } if (UNInput.GetButtonDown(playerData.ID, ButtonCode.B)) { if (catchBlock) { StartCoroutine(ThrowRoutine(0.75f)); } } }
public void Movement() { if (Time.time < delay) { return; } movement.x = UNInput.GetAxis(playerData.ID, AxisCode.LeftStickHorizontal); movement.y = UNInput.GetAxis(playerData.ID, AxisCode.LeftStickVertical); transform.rotation = Quaternion.LookRotation( new Vector3( movement.x, 0.0f, movement.y ), Vector3.up ); if (controller.isGrounded) { moveDirection = new Vector3( Mathf.Abs(movement.x) > .4f ? movement.x : 0f, 0.0f, Mathf.Abs(movement.y) > .4f ? movement.y : 0f); //moveDirection = transform.TransformDirection(moveDirection); moveDirection = moveDirection.normalized * playerData.speed; } // Apply gravity moveDirection.y = moveDirection.y - (playerData.gravity * Time.deltaTime); // Move the controller controller.Move(moveDirection * Time.deltaTime); //transform.rotation = Quaternion.LookRotation(moveDirection, Vector3.up); //if (catchBlock) //{ // catchBlock.transform.position = new Vector3(transform.position.x, 4f, transform.position.z); //} }
// Update is called once per frame void Update() { for (int i = 0; i < players.Length; i++) { players[i].Update(); } for (int i = 0; i < remainingInputs.Count; i++) { if (UNInput.GetButtonDown(remainingInputs[i], "Action")) { ClickedJoined(remainingInputs[i]); remainingInputs.Remove(remainingInputs[i]); } } if (keyboardAvailable && Input.GetKeyDown(KeyCode.Space)) { ClickedJoined(-1); keyboardAvailable = false; } }
private void CatchBlock() { if (catchBlock) { return; } if (interactBlock && guide) { guide.Grab(); } if (!interactBlock && guide) { guide.Clear(); } if (UNInput.GetButtonDown(playerData.ID, ButtonCode.A)) { if (interactBlock) { StartCoroutine(GrabRoutine(0.1f)); } } }
public void Update() { if (!hasClicked) { return; } if (joystickID == -1) { if (Input.GetKeyDown(KeyCode.Escape)) { Back(); } if (Input.GetKeyDown(KeyCode.Space)) { Ready(); } } else { UNInput.GetInputReference(joystickID, out vi); if (!vi.connected) { Unready(); Unjoin(); return; } if (UNInput.GetButtonDown(joystickID, "Back")) { Back(); } if (UNInput.GetButtonDown(joystickID, "Action")) { Ready(); } } }
// Update is called once per frame private void Update() { for (i = 0; i < 8; i++) { VirtualInput vi; int id = UNInput.GetInputIndex("Hardware Joystick " + i.ToString()); if (UNInput.GetInputReference(id, out vi)) { if (vi.connected) { if (gamepadType == GamepadType.AndroidGamepad) { /*if (((NetworkInput)vi)) //Checar se é Mobile * { * Axes(id); * Buttons(id); * }*/ } else if (gamepadType == GamepadType.XBoxGamepad) { if (((HardwareInput)vi).type == HardwareInput.HardwareType.Xbox) { Axes(id, xbox); Buttons(id, xbox); } } else if (gamepadType == GamepadType.PlayStationGamepad) { if (((HardwareInput)vi).type == HardwareInput.HardwareType.Playstation) { Axes(id, playstation); Buttons(id, playstation); } } } } } }
private void Update() { if (UNInput.GetButtonDown(ButtonCode.Start)) { if (playersActivated.Count > 0) { SceneManager.LoadScene(1); } } for (int id = 0; id < 4; id++) { if (playersActivated.Contains(id)) { horizontal = UNInput.GetAxis(players[id].playerData.ID, AxisCode.LeftStickHorizontal); vertical = UNInput.GetAxis(players[id].playerData.ID, AxisCode.LeftStickVertical); if (Mathf.Abs(horizontal) > .55f) { if (horizontal > 0f) { players[id].IncrementModel(); } else { players[id].DecrementModel(); } } if (Mathf.Abs(vertical) > .55f) { if (vertical > 0f) { players[id].IncrementSkin(); } else { players[id].DecrementSkin(); } } continue; } blockCheck = false; if (UNInput.GetButtonDown(id, ButtonCode.B)) { for (int i = 0; i < 4; i++) { if (players[i].IsActive()) { continue; } menuController.ChooseToMenu(); Invoke("Start", 1f); blockCheck = true; break; } } if (UNInput.GetButtonDown(id, ButtonCode.A)) { for (int i = 0; i < 4; i++) { if (players[i].IsActive()) { continue; } players[i].ActivePlayer(id, false); playersActivated.Add(id); blockCheck = true; break; } } if (blockCheck) { break; } } }
public void SetAxisNeutralState() { UNInput.SetAxisZero(input_id, Name); }
public void SetAxisNegativeState() { UNInput.SetAxisNegative(input_id, Name); }
public void SetUpState() { UNInput.SetButtonUp(input_id, Name); }
void Buttons(int id, Gamepad game) { //Back if (UNInput.GetButton(id, ButtonCode.Back)) { game._select.color = game.select; } else { game._select.color = Color.white; } //Start if (UNInput.GetButton(id, ButtonCode.Start)) { game._start.color = game.start; } else { game._start.color = Color.white; } //A if (UNInput.GetButton(id, ButtonCode.A)) { game._ex.color = game.ex; } else { game._ex.color = Color.white; } //B if (UNInput.GetButton(id, ButtonCode.B)) { game._circle.color = game.circle; } else { game._circle.color = Color.white; } //X if (UNInput.GetButton(id, ButtonCode.X)) { game._quad.color = game.quad; } else { game._quad.color = Color.white; } //Y if (UNInput.GetButton(id, ButtonCode.Y)) { game._triangle.color = game.triangle; } else { game._triangle.color = Color.white; } //Left Stick Click if (UNInput.GetButton(id, ButtonCode.LS)) { game._l3.color = game.l3; } else { game._l3.color = Color.white; } //Right Stick Click if (UNInput.GetButton(id, ButtonCode.RS)) { game._r3.color = game.r3; } else { game._r3.color = Color.white; } //Left Bumper if (UNInput.GetButton(id, ButtonCode.LB)) { game._l1.color = game.l1; } else { game._l1.color = Color.white; } //Right Bumper if (UNInput.GetButton(id, ButtonCode.RB)) { game._r1.color = game.r1; } else { game._r1.color = Color.white; } //DPad Right if (UNInput.GetButton(id, ButtonCode.DPadRight)) { game._dpadRight.color = game.dpadRight; } else { game._dpadRight.color = Color.white; } //DPad Left if (UNInput.GetButton(id, ButtonCode.DPadLeft)) { game._dpadLeft.color = game.dpadLeft; } else { game._dpadLeft.color = Color.white; } //DPad Up if (UNInput.GetButton(id, ButtonCode.DPadUp)) { game._dpadUp.color = game.dpadUp; } else { game._dpadUp.color = Color.white; } //DPad Down if (UNInput.GetButton(id, ButtonCode.DPadDown)) { game._dpadDown.color = game.dpadDown; } else { game._dpadDown.color = Color.white; } }
// Update is called once per frame void Update() { if (!isComplete) { switch (puzzleType) { case PuzzleType.Press: if (UNInput.GetButtonDown(controllerID, randButton[buttonSelected])) { percentage += percentageIncrease; if (percentage >= 100.0f) { Debug.Log("Completed"); isComplete = true; } } percentage -= percentageDecrease * Time.deltaTime; percentage = Mathf.Abs(percentage); progressValue.value = percentage / 100f; break; case PuzzleType.Alternate: if (UNInput.GetButtonDown(controllerID, nextPress)) { nextPress = nextPress != altButton[0] ? altButton[0] : altButton[1]; percentage += percentageIncrease; if (percentage >= 100.0f) { Debug.Log("Completed"); isComplete = true; } } percentage -= percentageDecrease * Time.deltaTime; percentage = Mathf.Abs(percentage); progressValue.value = percentage / 100f; break; case PuzzleType.Combination: if (resetTimer >= resetTime) { ResetCombination(); } foreach (ButtonCode button in allButtons) { if (!UNInput.GetButtonDown(controllerID, button)) { continue; } Debug.Log(button); if (button != combButtons[combCount]) { ResetCombination(); resetTimer = 0.0f; } else { combCount++; } transform.GetChild(2).GetChild(1).GetComponentInChildren <ButtonCodeWriter>().SetText(combCount); if (combCount >= combButtons.Length) { Debug.Log("Completed"); isComplete = true; break; } } resetTimer += Time.deltaTime; break; } } }
void Start() { input_id = UNInput.GetInputIndex("Network Control"); }
/// <summary> /// Move the player. /// </summary> /// <param name="i"> id of the joystic that is going to move this player. </param> public void Move(int i) { if (canMove)//Se o jogador pode se movimentar { if (usingKeyboard) { movement = Vector3.zero; if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W)) { movement += Vector3.forward; } if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S)) { movement += Vector3.back; } if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A)) { movement += Vector3.left; } if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D)) { movement += Vector3.right; } //Setando movimentação } else { movement = new Vector3(UNInput.GetAxis(i, AxisCode.LSH), 0f, UNInput.GetAxis(i, AxisCode.LSV)); //Setando movimentação } if (movement.magnitude < 0.2f) //Se a movementação for pequena(correção do analógico) { movement = Vector3.zero; //Zerando movimentação } else { transform.rotation = Quaternion.identity * Quaternion.LookRotation(movement, Vector3.up); //Atualizando a rotação } if (controller.isGrounded) //Se estiver colidindo com o chão { doubleJumping = false; //Pode pular a segunda vez if (canJump) //Se pode pular { if (UNInput.GetButtonDown(i, ButtonCode.A) || (Input.GetKeyDown(KeyCode.KeypadEnter) && usingKeyboard)) //Se o jogador apertar o botão de pulo { Jump(); //Função de pulo } } } else //Se não estiver no chão { if (canDoubleJump)//Se puder pular uma segunda vez { if (!doubleJumping) //Se ainda não pulou o segundo pulo { if (UNInput.GetButtonDown(i, ButtonCode.A) || (Input.GetKeyDown(KeyCode.KeypadEnter) && usingKeyboard)) //Se o jogador apertar o botão de pulo { Jump(); //Função de pulo doubleJumping = true; //pulou segundo pulo } } } } gravity += Vector3.down * forceGravity * Time.deltaTime; //Adicionando a gravidade controller.Move(((transform.rotation * Vector3.forward * currentSpeed) * movement.magnitude * Time.deltaTime) + (gravity * Time.deltaTime)); //Movimentando } else { controller.Move(gravity * Time.deltaTime); //Somente Adicionar a gravidade } if (gravity.y < -forceGravity) //Se a gravidade for maior que a força gravitacional { gravity = Vector3.down * forceGravity; //Setando o valor máximo da gravidade } }
public void SetDownState() { UNInput.SetButtonDown(input_id, Name); }