public void Update() { // checks if both players controllers are true if (XboxController1.useController == true || XboxController2.useController == true) { // if the pause, game win and game over screens are not on the screen THEN if (pause.paused == false && manager.gameWin.winGameScreen.activeInHierarchy == false && manager.gameOver.DeathScreen.activeInHierarchy == false) { // the players can turn on the scoreboard screen // bringing up the score board if (XCI.GetButton(XboxButton.Back, XboxController1.controller) || XCI.GetButton(XboxButton.Back, XboxController2.controller)) { scoreBoard.SetActive(true); } // if the button is released the scoreboard will disappear from the screen else if (XCI.GetButtonUp(XboxButton.Back, XboxController1.controller) || XCI.GetButtonUp(XboxButton.Back, XboxController2.controller)) { scoreBoard.SetActive(false); } } } // updates both scores SizzleScoreBoard(); ChunkScoreBoard(); }
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // launches the punch after the player has wound up a punch void Punch() { if (XCI.GetButtonUp(punchButton, controller)) // when the bumper is released... { fist.enabled = true; // enables the fist so it can start colliding with things if (canPunch == true) // if the player can punch (have wound up enough)... { punchDuration = 0.0f; // reset the punch duration timer canPunch = false; // the player can no longer punch fistRB.AddForce(punchVector * punchSpeed); // apply force to the fist, to move it forward windUpTimer = 0.0f; // reset how long you have to wind up a punch before you can fire } canWindUp = false; // make player unable to wind up another punch WindUpCooldown(); // invoke the WindUpCooldown() function } // how long the punch will go for punchDuration += Time.deltaTime; // punch duration ticks up if (punchDuration >= punchDurationLimit) // once the punch has been out for long enough... { transform.position = fistReset.transform.position; // teleport the punch back to the reset point fistRB.velocity = Vector3.zero; // reset the velocity of the fist fistRB.angularVelocity = Vector3.zero; // reset the angular velocity of the fist fist.enabled = false; punchLight.SetActive(false); // turns off the light attached to the fists } }
// Update is called once per frame void Update() { inputVec = new Vector2(XCI.GetAxis(XboxAxis.LeftStickX, (XboxController)playerIndex), XCI.GetAxis(XboxAxis.LeftStickY, (XboxController)playerIndex)); if (XCI.GetButtonUp(XboxButton.LeftStick, (XboxController)playerIndex)) { Movement.initiateSneak(); } if (XCI.GetButton(XboxButton.A, (XboxController)playerIndex) && Movement.jumpStates != Movement.JUMPSTATES.JUMPING) { Movement.jumpStates = Movement.JUMPSTATES.JUMPPREP; Movement.jumpPreparation(); } if (XCI.GetButtonUp(XboxButton.A, (XboxController)playerIndex) && Movement.jumpStates != Movement.JUMPSTATES.JUMPING) { Movement.jumpStates = Movement.JUMPSTATES.LAUNCH; } if (XCI.GetButton(XboxButton.Y, (XboxController)playerIndex)) { GetComponent <Abilities>().triggerEnemies(); } }
private void Update() { if (playerNumber != -1) { if (XCI.GetAxis(XboxAxis.LeftStickX, xboxController) < -0.2f) { if (canSwap) { Left(); } } else if (XCI.GetAxis(XboxAxis.LeftStickX, xboxController) > 0.2f) { if (canSwap) { Right(); } } if (XCI.GetButtonUp(XboxButton.A, xboxController)) { if (canConfirm) { CharacterSelection.instance.Confirm(playerNumber, activeChar, transform.position, xboxController); } } if (XCI.GetButtonUp(XboxButton.B, xboxController)) { canConfirm = false; characters[activeChar].gameObject.SetActive(false); //activeChar = 0; Commented out so that the previous choice of the player is remembered CharacterSelection.instance.Leave(playerNumber); playerNumber = 0; } } }
// Update is called once per frame void Update() { if (XCI.GetButtonUp(XboxButton.A)) { Application.LoadLevel(levelToLoad); } }
// Update is called once per frame void Update() { if (XCI.GetButtonUp(continueButton)) { SceneManager.LoadSceneAsync("Main", LoadSceneMode.Single); } }
// Update is called once per frame private void Update() { if (XCI.GetButtonUp(XboxButton.A, XboxController.First) && !playerActive[0]) { playerActive[0] = true; characterSelectionControllers[0].Activate(0); } if (XCI.GetButtonUp(XboxButton.A, XboxController.Second) && !playerActive[1]) { playerActive[1] = true; characterSelectionControllers[1].Activate(1); } if (XCI.GetButtonUp(XboxButton.A, XboxController.Third) && !playerActive[2]) { playerActive[2] = true; characterSelectionControllers[2].Activate(2); } if (XCI.GetButtonUp(XboxButton.A, XboxController.Fourth) && !playerActive[3]) { playerActive[3] = true; characterSelectionControllers[3].Activate(3); } if (playerActive[0] && playerActive[1] && playerActive[2] && playerActive[3]) { toJoin.gameObject.SetActive(true); } if (playerActive[0] || playerActive[1] || playerActive[2] || playerActive[3]) { selectChar.gameObject.SetActive(true); } else { selectChar.gameObject.SetActive(false); } }
//Move the character with WASD void Controls() { if (Input.GetKey(KeyCode.W)) { transform.position += transform.forward * moveSpeed * Time.deltaTime; } else if (Input.GetKey(KeyCode.S)) { transform.position -= transform.forward * moveSpeed * Time.deltaTime; } if (Input.GetKey(KeyCode.A)) { transform.position -= transform.right * moveSpeed * Time.deltaTime; } else if (Input.GetKey(KeyCode.D)) { transform.position += transform.right * moveSpeed * Time.deltaTime; } if (Input.GetKey(KeyCode.Space) || XCI.GetButton(XboxButton.X)) { transform.position += Vector3.up * moveSpeed * Time.deltaTime; } if (Input.GetKey(KeyCode.LeftControl) || XCI.GetButton(XboxButton.B)) { transform.position -= Vector3.up * moveSpeed * Time.deltaTime; } if (Input.GetMouseButtonUp(0) || XCI.GetButtonUp(XboxButton.RightBumper)) { LeftMouseClick(); ui.charger.SetActive(false); } if (Input.GetMouseButton(0) || XCI.GetButton(XboxButton.RightBumper)) { buttonHeld += (Time.deltaTime); ui.charger.SetActive(true); runOnce = false; } else { buttonHeld = 0; } if (Input.GetMouseButtonDown(1) || XCI.GetButtonDown(XboxButton.LeftBumper)) { int lastLine = spawnedLineList.Count - 1; Destroy(spawnedLineList[lastLine]); spawnedLineList.RemoveAt(lastLine); } if (Input.GetKeyDown(KeyCode.Escape) || XCI.GetButtonDown(XboxButton.Start)) { Application.Quit(); } if (Input.GetKeyDown(KeyCode.R) || XCI.GetButtonDown(XboxButton.Back)) { SceneManager.LoadScene("TestMirror"); } }
void RaycastWorldUI() { if (XCI.GetButtonDown(XboxButton.A)) { print(transform.position); PointerEventData pointerData = new PointerEventData(EventSystem.current); pointerData.position = transform.position; //camera.WorldToScreenPoint(transform.position);//Input.mousePosition; List <RaycastResult> results = new List <RaycastResult>(); EventSystem.current.RaycastAll(pointerData, results); print(results.Count); if (results.Count > 1) { // print("true"); // foreach (RaycastResult result in results) { for (int ii = 1; ii < 6 && ii < results.Count; ii++) { //only need to hit object at index 1 cause that's the highest up object // print(results[1].gameObject.name + ", " + results[1].index); ExecuteEvents.Execute(results[ii].gameObject, pointerData, ExecuteEvents.pointerDownHandler); // ExecuteEvents.Execute(results[ii].gameObject, pointerData, ExecuteEvents.pointerClickHandler); ExecuteEvents.Execute(results[ii].gameObject, pointerData, ExecuteEvents.beginDragHandler); ExecuteEvents.Execute(results[ii].gameObject, pointerData, ExecuteEvents.initializePotentialDrag); } } } else if (XCI.GetButtonUp(XboxButton.A)) { print(transform.position); PointerEventData pointerData = new PointerEventData(EventSystem.current); pointerData.position = transform.position; //camera.WorldToScreenPoint(transform.position);//Input.mousePosition; List <RaycastResult> results = new List <RaycastResult>(); EventSystem.current.RaycastAll(pointerData, results); // print(results.Count); if (results.Count > 1) { // print("true"); // foreach (RaycastResult result in results) { for (int ii = 1; ii < 6 && ii < results.Count; ii++) { ExecuteEvents.Execute(results[ii].gameObject, pointerData, ExecuteEvents.pointerUpHandler); ExecuteEvents.Execute(results[ii].gameObject, pointerData, ExecuteEvents.pointerClickHandler); ExecuteEvents.Execute(results[ii].gameObject, pointerData, ExecuteEvents.endDragHandler); } // } } } }
void Update() { //Ensures there is always a selected menu option if (isPaused && EventSystem.current.currentSelectedGameObject == null) { EventSystem.current.SetSelectedGameObject(startOption); } //Checks if any of the players press start to open the pause menu if (XCI.GetButtonDown(XboxButton.Start, XboxController.First) || XCI.GetButtonDown(XboxButton.Start, XboxController.Second) || XCI.GetButtonDown(XboxButton.Start, XboxController.Third) || XCI.GetButtonDown(XboxButton.Start, XboxController.Fourth)) { //If a player presses the pause button while they are in the pause menu, //they are returned to the game if (isPaused) { gameCanvas.transform.GetChild(0).gameObject.SetActive(true); gameCanvas.transform.GetChild(1).gameObject.SetActive(true); gameCanvas.transform.GetChild(2).gameObject.SetActive(true); EventSystem.current.SetSelectedGameObject(null); pauseCanvas.transform.GetChild(0).gameObject.SetActive(false); Time.timeScale = 1f; isPaused = false; } //If the pause button is pressed while in the game, the pause menu is opened else { gameCanvas.transform.GetChild(0).gameObject.SetActive(false); gameCanvas.transform.GetChild(1).gameObject.SetActive(false); gameCanvas.transform.GetChild(2).gameObject.SetActive(false); pauseCanvas.transform.GetChild(0).gameObject.SetActive(true); EventSystem.current.SetSelectedGameObject(startOption); Time.timeScale = 0f; UpdateScoreBoard(); isPaused = true; } } //If any of the players press B from the pause menu, they will be sent back to the game if (isPaused && XCI.GetButtonUp(XboxButton.B, XboxController.First) || XCI.GetButtonUp(XboxButton.B, XboxController.Second) || XCI.GetButtonUp(XboxButton.B, XboxController.Third) || XCI.GetButtonUp(XboxButton.B, XboxController.Fourth)) { gameCanvas.transform.GetChild(0).gameObject.SetActive(true); gameCanvas.transform.GetChild(1).gameObject.SetActive(true); gameCanvas.transform.GetChild(2).gameObject.SetActive(true); pauseCanvas.transform.GetChild(0).gameObject.SetActive(false); Time.timeScale = 1f; isPaused = false; } }
// Update is called once per frame void Update() { if (GetComponent <Player>().IsDead() && m_playerGhostHolder == null) { //Decide which ghost to spawn if (GetComponent <ColourController>().m_firstBulletSlot) { m_playerGhostHolder = Instantiate(m_playerGhost, transform.TransformPoint(m_playerGhostOffset), Quaternion.identity, transform); //Ghost Destroy(Instantiate(m_playerDeathEffect[0], transform.TransformPoint(m_playerDeathEffectOffset), Quaternion.identity, transform), 5.0f); //Death effect } else { m_playerGhostHolder = Instantiate(m_playerGhost, transform.TransformPoint(m_playerGhostOffset), Quaternion.identity, transform); //Ghost Destroy(Instantiate(m_playerDeathEffect[1], transform.TransformPoint(m_playerDeathEffectOffset), Quaternion.identity, transform), 5.0f); //Death effect } GetComponent <PlayerSounds> ().m_deathAudio.GetComponent <AudioSource> ().Play(); //Play death sound for player this.gameObject.GetComponent <Player> ().m_childRenderer.GetComponentInChildren <SkinnedMeshRenderer> ().enabled = false; //Set player to be transparent } else if (!GetComponent <Player> ().IsDead() && m_playerGhostHolder != null) { this.gameObject.GetComponent <Player> ().m_childRenderer.GetComponentInChildren <SkinnedMeshRenderer> ().enabled = true; //Set player to not be transparent Destroy(m_playerGhostHolder); } if (isReviving && XCI.GetButton((XboxButton.X), controller) && !GetComponent <Player> ().IsDead() && m_otherPlayer.GetComponent <Player> ().IsDead()) { timer += Time.deltaTime; if (timer >= reviveTime) { timer = 0; //Revivie other player, play sound m_otherPlayer.GetComponent <Player> ().SetHealth(2); m_otherPlayer.GetComponent <PlayerSounds> ().m_reviveAudio.GetComponent <AudioSource> ().Play(); PlayerHealth otherPlayerHealth = m_otherPlayer.GetComponent <PlayerHealth>(); Destroy(Instantiate(otherPlayerHealth.m_playerReviveEffect, m_otherPlayer.transform.TransformPoint(otherPlayerHealth.m_playerReviveEffectOffset), Quaternion.identity, otherPlayerHealth.transform), 5.0f); //Death effect } //Play Audio for respawn if (!m_playerSounds.m_respawnAudio.GetComponent <AudioSource> ().isPlaying) { m_playerSounds.m_respawnAudio.GetComponent <AudioSource> ().Play(); } } if (XCI.GetButtonUp((XboxButton.B), controller)) { timer = 0; } }
private void Update() { if (XCI.GetButton(XboxButton.A, controller) && Time.time >= nextTimeToFire) { nextTimeToFire = Time.time + 1f / fireRate; Shoot(); } if (XCI.GetButtonUp(XboxButton.A, controller)) { muzzleFlash.SetActive(false); light.SetActive(false); } }
/// <summary> /// Checks if shoot inputs have been pressed / released. Sets the animator accordingly. /// </summary> void CheckInputs() { if (XCI.GetButtonDown(XboxButton.X, myController.GetID()) || Input.GetKeyDown(KeyCode.F)) { myController.SetCharging(true); strength = minStrength; // TODO: shot feints in pass } else if (XCI.GetButtonUp(XboxButton.X, myController.GetID()) || Input.GetKeyUp(KeyCode.F)) { myController.SetCharging(false); shoot = true; } }
// Update is called once per frame void Update() { if (XCI.GetButtonUp(XboxButton.Start)) { onPause = !onPause; } if (onPause) { Time.timeScale = 0; } else { Time.timeScale = 1; } }
private void Update() { if (XCI.GetButton(XboxButton.A, controller)) { Shoot(); } if (XCI.GetButtonUp(XboxButton.A, controller)) { flame.Stop(); if (flame2) { flame2.Stop(); } } }
//---------------------------------------------------------------------- // MovePlayer() // Moves the player // // Param: // None // Return; // Void //---------------------------------------------------------------------- private void MovePlayer() { transform.position += transform.forward * constantThrust * Time.deltaTime; if (XCI.GetAxis(XboxAxis.LeftTrigger, controller) != 0) { transform.position += transform.forward * boosterThrust * Time.deltaTime; } if (inputLeftStickY < 0) { transform.Rotate((inputLeftStickY) * pitchSpeed * Time.deltaTime, 0, 0); } if (inputLeftStickY > 0) { transform.Rotate((inputLeftStickY) * pitchSpeed * Time.deltaTime, 0, 0); } if (inputRightStickX < 0) { transform.Rotate((inputLeftStickX) * 0, 0, rollSpeed * Time.deltaTime); } if (inputRightStickX > 0) { transform.Rotate((inputLeftStickX) * 0, 0, -rollSpeed * Time.deltaTime); } if (inputLeftStickX < 0) { transform.Rotate((inputRightStickX) * 0, -yawSpeed * Time.deltaTime, 0); } if (inputLeftStickX > 0) { transform.Rotate((inputRightStickX) * 0, yawSpeed * Time.deltaTime, 0); } if (XCI.GetButton(XboxButton.A, controller)) { rearCamera.SetActive(true); } if (XCI.GetButtonUp(XboxButton.A, controller)) { rearCamera.SetActive(false); } }
private void OnTriggerStay(Collider other) { if (other.gameObject.tag == "Vendor") { ShopScript.ShopText.SetActive(true); Debug.Log("VENDORCOLLISIION"); if (XCI.GetButtonUp(XboxButton.B) && CanShop) { Debug.Log("Vendor ignores you"); CanMove = false; ShopScript.menu.SetActive(true); InMenu = true; ShopScript.ShopCam.SetActive(true); } } }
public static bool GetTribeButtonUp(int tribe, int player) { if (XCI.GetNumPluggedCtrlrs() > player) { return(XCI.GetButtonUp(TribeButton(tribe), player + 1)); } else if (player == 0) { return(Input.GetKeyUp(TribePlayerOneKey(tribe))); } else if (player == 1) { return(Input.GetKeyUp(TribePlayerTwoKey(tribe))); } else { return(false); } }
private void GetInput() { if (_IsUsingController) { _HorizontalAxis = XCI.GetAxis(XboxAxis.LeftStickX, controller); _VerticalAxis = XCI.GetAxis(XboxAxis.LeftStickY, controller); _LTrigger = 1 * XCI.GetAxis(XboxAxis.LeftTrigger, controller); _RTrigger = 1 * XCI.GetAxis(XboxAxis.RightTrigger, controller); _AButton = XCI.GetButton(XboxButton.A); _BButton = XCI.GetButton(XboxButton.B); _XButton = XCI.GetButton(XboxButton.X); _YButton = XCI.GetButton(XboxButton.Y); _DPadUp = XCI.GetButton(XboxButton.DPadUp); _DPadDown = XCI.GetButton(XboxButton.DPadDown); _DPadLeft = XCI.GetButton(XboxButton.DPadLeft); _DPadRight = XCI.GetButton(XboxButton.DPadRight); _BumperLeft = XCI.GetButton(XboxButton.LeftBumper); _BumperRight = XCI.GetButton(XboxButton.RightBumper); if (XCI.GetButtonDown(XboxButton.X)) { _FrictionMultiplier = _FrictionMultiplier * 1.5f; } if (XCI.GetButtonUp(XboxButton.X)) { _FrictionMultiplier = _FrictionMultiplier / 1.5f; } } if (_IsUsingController == false) { _RTrigger = Input.GetAxis("Vertical"); _HorizontalAxis = Input.GetAxis("Horizontal"); if (Input.GetKeyDown(KeyCode.E)) { _FrictionMultiplier = _FrictionMultiplier * 1.5f; } if (Input.GetKeyUp(KeyCode.E)) { _FrictionMultiplier = _FrictionMultiplier / 1.5f; } } }
void ButtonControlsXInput(int i) { XboxButton val = myXCIButtons[i].GetXboxButtonCode(); if (XCI.GetButtonDown(val, xboxController)) { if (s_GameManager.ShowDebug() || ShowDebug) { Debug.Log(val.ToString() + " is value of down"); } myXCIButtons[i].Execute(); } if (XCI.GetButtonUp(val, xboxController)) { if (s_GameManager.ShowDebug() || ShowDebug) { Debug.Log(val.ToString() + " is value of up"); } myXCIButtons[i].ExecuteOnUp(); } }
// If there is a downed player in this player's range, begin reviving the player void ReviveAction() { // If the downed player is not equal to null if (downedPlayer != null) { // Gets reference to downed player's revive bar Slider bar = downedPlayer.reviveBar; // If the player holds the X button on the downed player... if (XCI.GetButton(XboxButton.X, player)) { downedPlayer.Revive(); // if the player is revived, lose the reference to the downed player if (reviveBar.value >= reviveBar.maxValue) { downedPlayer = null; } } // If revive button is let go... else if (XCI.GetButtonUp(XboxButton.X, player)) { // Stop reviving player downedPlayer.StopReviving(); // If the button is let go, the progress is reset bar.value -= 0.0025f; if (bar.value <= bar.minValue) { bar.value = bar.minValue; } // If the button is let go, the progress is reset bar.value -= 0.0025f; if (bar.value <= bar.minValue) { bar.value = bar.minValue; } } } }
private void Update() { //get input from box controller horizontalInput = XCI.GetAxis(XboxAxis.LeftStickX, player); verticalInput = XCI.GetAxis(XboxAxis.LeftStickY, player); camHorizontalInput = XCI.GetAxis(XboxAxis.RightStickY, player); camVerticalInput = XCI.GetAxis(XboxAxis.RightStickX, player); //create Vector3 input collect the val. Vector3 input = new Vector3(horizontalInput, 0, verticalInput) * speed * sprintSpeed; //ClampMagnitude make it to be same value in every direction input = Vector3.ClampMagnitude(input, speed * sprintSpeed); //Check input from controller and do something if (XCI.GetButtonDown(sprintBt, player)) { //Q? sprintSpeed = 2; //TODO set every state doning faster } if (XCI.GetButtonUp(sprintBt, player)) { sprintSpeed = 1; //TODO reset to normal state } if (XCI.GetButtonDown(jumpBt, player)) { input.y = jumpHeight; //TODO set jumo animation } //if not jump Player Y velocity is what they was before else { input.y = rb.velocity.y; } //change Player velocity rb.velocity = transform.InverseTransformVector(input); }
private void GetInput() { if (XCI.IsPluggedIn(controller)) { _AccelAxis = XCI.GetAxis(XboxAxis.RightTrigger, controller); _BrakeAxis = XCI.GetAxis(XboxAxis.LeftTrigger, controller); _SteerAxis = XCI.GetAxis(XboxAxis.LeftStickX, controller); _DriftButtonUp = XCI.GetButtonUp(XboxButton.X, controller); _DriftButtonDown = XCI.GetButtonDown(XboxButton.X, controller); _DriftButtonHeld = XCI.GetButton(XboxButton.X, controller); } else { _AccelAxis = Input.GetAxis("Vertical"); _SteerAxis = Input.GetAxis("Horizontal"); _DriftButtonUp = Input.GetKeyUp(KeyCode.Space); _DriftButtonDown = Input.GetKeyDown(KeyCode.Space); _DriftButtonHeld = Input.GetKey(KeyCode.Space); } }
// Update is called once per frame void Update() { if (_target == null) { Destroy(gameObject); } if (XCI.GetAxis(XboxAxis.LeftStickX, ctlr) != 0 || XCI.GetAxis(XboxAxis.LeftStickY, ctlr) != 0) { _target.transform.parent = null; _target.GetComponent <PlayerMove>().enabled = true; } if (XCI.GetButtonUp(XboxButton.LeftBumper, ctlr)) { hand = 1f; attachOld(step_size); } if (XCI.GetButtonUp(XboxButton.RightBumper, ctlr)) { hand = -1f; attachOld(step_size); } }
// Update is called once per frame void Update() { // If player has an xbox controllor, then handle input with controller buttons: if (handler.HasAssignedController) { if (XCI.GetButtonDown(buttonBind, handler.AssignedController)) { currentScoreUI.SetActive(true); playerHUD.SetActive(false); } if (XCI.GetButtonUp(buttonBind, handler.AssignedController)) { currentScoreUI.SetActive(false); playerHUD.SetActive(true); } } else { // If no xbox controller connected, fallback to keyboard input. if (Input.GetKeyDown(keybind)) { currentScoreUI.SetActive(true); playerHUD.SetActive(false); } if (Input.GetKeyUp(keybind)) { currentScoreUI.SetActive(false); playerHUD.SetActive(true); } } if (score != null) { score.text = handler.PlayerStats.TotalScore.ToString(); } }
protected override void NewUpdate() { base.NewUpdate(); if (XCI.GetButtonDown(XboxButton.LeftBumper, playerNumber)) { CurrentSlowShot = ShootSlowBubble(); } if (XCI.GetButtonDown(XboxButton.RightBumper, playerNumber)) { CurrentFastShot = ShootFastBubble(); } if (XCI.GetButtonDown(XboxButton.A, playerNumber) && CoolDownA <= 0) { ShootBullet(); } if (XCI.GetButtonDown(XboxButton.X, playerNumber)) { tankSpecial.SpecialX(); } if (XCI.GetButtonDown(XboxButton.Y, playerNumber)) { tankSpecial.SpecialY(); } if (XCI.GetButtonDown(XboxButton.B, playerNumber)) { tankSpecial.SpecialB(); } if (CurrentSlowShot != null && XCI.GetButtonUp(XboxButton.LeftBumper, playerNumber)) { CurrentSlowShot.Detonate(); } if (CurrentFastShot != null && XCI.GetButtonUp(XboxButton.RightBumper, playerNumber)) { CurrentFastShot.Detonate(); } }
public bool buttonUp(int player_num, string button) { XboxController player; if (player_num == 1) { player = player01; } else if (player_num == 2) { player = player02; } else { return(false); } switch (button) { case "A": return(XCI.GetButtonUp(XboxButton.A, player)); case "B": return(XCI.GetButtonUp(XboxButton.B, player)); case "X": return(XCI.GetButtonUp(XboxButton.X, player)); case "Y": return(XCI.GetButtonUp(XboxButton.Y, player)); case "RB": return(XCI.GetButtonUp(XboxButton.RightBumper, player)); case "LB": return(XCI.GetButtonUp(XboxButton.LeftBumper, player)); case "Start": return(XCI.GetButtonUp(XboxButton.Start, player)); case "Back": return(XCI.GetButtonUp(XboxButton.Back, player)); case "R3": return(XCI.GetButtonUp(XboxButton.RightStick, player)); case "L3": return(XCI.GetButtonUp(XboxButton.LeftStick, player)); case "N": return(XCI.GetButtonUp(XboxButton.DPadUp, player)); case "E": return(XCI.GetButtonUp(XboxButton.DPadRight, player)); case "S": return(XCI.GetButtonUp(XboxButton.DPadDown, player)); case "W": return(XCI.GetButtonUp(XboxButton.DPadLeft, player)); default: return(false); } }
// Update void Update() { GameObject bulletReference = null; // Jump (Left Stick) if (XCI.GetButtonDown(XboxButton.LeftStick, playerNumber) && canJump) { canJump = false; GetComponent <Rigidbody>().AddRelativeForce(0.0f, jumpImpulse, 0.0f, ForceMode.Impulse); } // Slam (Right Stick) if (XCI.GetButtonDown(XboxButton.RightStick, playerNumber) && !canJump) { GetComponent <Rigidbody>().AddRelativeForce(0.0f, (-jumpImpulse * 1.5f), 0.0f, ForceMode.Impulse); } // Shoot colored laser (A,B,X,Y) if (bulletTimer > 0.0f) { bulletTimer -= Time.deltaTime; } if (bulletTimer <= 0.0f) { if (XCI.GetButton(XboxButton.A, playerNumber)) { Instantiate(laserAPrefab, transform.position, laserAPrefab.transform.rotation); bulletTimer = MAX_BUL_TME; } if (XCI.GetButton(XboxButton.B, playerNumber)) { Instantiate(laserBPrefab, transform.position, laserBPrefab.transform.rotation); bulletTimer = MAX_BUL_TME; } if (XCI.GetButton(XboxButton.X, playerNumber)) { Instantiate(laserXPrefab, transform.position, laserXPrefab.transform.rotation); bulletTimer = MAX_BUL_TME; } if (XCI.GetButton(XboxButton.Y, playerNumber)) { Instantiate(laserYPrefab, transform.position, laserYPrefab.transform.rotation); bulletTimer = MAX_BUL_TME; } } // Left stick movement newPosition = transform.position; float axisX = XCI.GetAxis(XboxAxis.LeftStickX, playerNumber); float axisY = XCI.GetAxis(XboxAxis.LeftStickY, playerNumber); float newPosX = newPosition.x + (axisX * maxMoveSpeed * Time.deltaTime); float newPosZ = newPosition.z + (axisY * maxMoveSpeed * Time.deltaTime); newPosition = new Vector3(newPosX, transform.position.y, newPosZ); transform.position = newPosition; // Right stick movement newPosition = transform.position; axisX = XCI.GetAxis(XboxAxis.RightStickX, playerNumber); axisY = XCI.GetAxis(XboxAxis.RightStickY, playerNumber); newPosX = newPosition.x + (axisX * maxMoveSpeed * 0.3f * Time.deltaTime); newPosZ = newPosition.z + (axisY * maxMoveSpeed * 0.3f * Time.deltaTime); newPosition = new Vector3(newPosX, transform.position.y, newPosZ); transform.position = newPosition; // D-Pad testing if (dpUpBulletTimer > 0.0f) { dpUpBulletTimer -= Time.deltaTime; } if (dpDownBulletTimer > 0.0f) { dpDownBulletTimer -= Time.deltaTime; } if (dpLeftBulletTimer > 0.0f) { dpLeftBulletTimer -= Time.deltaTime; } if (dpRightBulletTimer > 0.0f) { dpRightBulletTimer -= Time.deltaTime; } if (dpUpBulletTimer <= 0.0f) { if (XCI.GetDPad(XboxDPad.Up, playerNumber)) { bulletReference = Instantiate(laserBumpPrefab, transform.position, laserYPrefab.transform.rotation) as GameObject; bulletReference.transform.localScale = new Vector3(0.1f, 0.1f, 1.0f); dpUpBulletTimer = MAX_BUL_TME * 2; } } if (dpDownBulletTimer <= 0.0f) { if (XCI.GetDPad(XboxDPad.Down, playerNumber)) { bulletReference = Instantiate(laserBumpPrefab, transform.position, laserAPrefab.transform.rotation) as GameObject; bulletReference.transform.localScale = new Vector3(0.1f, 0.1f, 1.0f); dpDownBulletTimer = MAX_BUL_TME * 2; } } if (dpLeftBulletTimer <= 0.0f) { if (XCI.GetDPad(XboxDPad.Left, playerNumber)) { bulletReference = Instantiate(laserBumpPrefab, transform.position, laserXPrefab.transform.rotation) as GameObject; bulletReference.transform.localScale = new Vector3(0.1f, 0.1f, 1.0f); dpLeftBulletTimer = MAX_BUL_TME * 2; } } if (dpRightBulletTimer <= 0.0f) { if (XCI.GetDPad(XboxDPad.Right, playerNumber)) { bulletReference = Instantiate(laserBumpPrefab, transform.position, laserBPrefab.transform.rotation) as GameObject; bulletReference.transform.localScale = new Vector3(0.1f, 0.1f, 1.0f); dpRightBulletTimer = MAX_BUL_TME * 2; } } // Trigger input float trigSclX = triggerLeftPrefab.transform.localScale.x; float trigSclZ = triggerLeftPrefab.transform.localScale.z; float leftTrigHeight = MAX_TRG_SCL * (1.0f - XCI.GetAxis(XboxAxis.LeftTrigger, playerNumber)); float rightTrigHeight = MAX_TRG_SCL * (1.0f - XCI.GetAxis(XboxAxis.RightTrigger, playerNumber)); triggerLeftPrefab.transform.localScale = new Vector3(trigSclX, leftTrigHeight, trigSclZ); triggerRightPrefab.transform.localScale = new Vector3(trigSclX, rightTrigHeight, trigSclZ); // Bumper input if (XCI.GetButtonDown(XboxButton.LeftBumper, playerNumber)) { Instantiate(laserBumpPrefab, triggerLeftPrefab.transform.position, laserBumpPrefab.transform.rotation); } if (XCI.GetButtonDown(XboxButton.RightBumper, playerNumber)) { Instantiate(laserBumpPrefab, triggerRightPrefab.transform.position, laserBumpPrefab.transform.rotation); } // Start and back, same as bumpers but smaller bullets if (XCI.GetButtonUp(XboxButton.Back, playerNumber)) { bulletReference = Instantiate(laserBumpPrefab, triggerLeftPrefab.transform.position, laserBumpPrefab.transform.rotation) as GameObject; bulletReference.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f); } if (XCI.GetButtonUp(XboxButton.Start, playerNumber)) { bulletReference = Instantiate(laserBumpPrefab, triggerRightPrefab.transform.position, laserBumpPrefab.transform.rotation) as GameObject; bulletReference.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f); } // To quit the program (with keyboard) if (Input.GetKeyUp(KeyCode.Escape)) { Application.Quit(); } }
private void Update() { if (inMainMenu) { if (canMove && Mathf.Abs(XCI.GetAxisRaw(XboxAxis.LeftStickY, XboxController.All)) > 0.5f) { buttons[currentButton].color = Color.black; if (XCI.GetAxisRaw(XboxAxis.LeftStickY, XboxController.All) > 0.0f) { currentButton = 0; } else { currentButton = 1; } buttons[currentButton].color = selectedColour; canMove = false; timeNextMove = Time.time + buttonSelectDelay; } if (XCI.GetButtonUp(XboxButton.A, XboxController.All)) { if (currentButton == 0) { MainMenu.SetActive(false); PlayerSelect.SetActive(true); inMainMenu = false; inSelectMenu = true; } if (currentButton == 1) { Application.Quit(); } } if (!canMove && Time.time > timeNextMove) { canMove = true; } } if (inSelectMenu) { // Player 1 if (!player1Ready) { // Move left/Right if (canMoveP1 && Mathf.Abs(XCI.GetAxisRaw(XboxAxis.LeftStickX, XboxController.First)) > 0.5f) { if (XCI.GetAxisRaw(XboxAxis.LeftStickX, XboxController.First) > 0.0f) { selectionGrid[player1Index.x, player1Index.y].sprite = defaultBorder; player1Index.x = MoveX(player1Index.x, 1); selectionGrid[player1Index.x, player1Index.y].sprite = playerOneHighlight; } else { selectionGrid[player1Index.x, player1Index.y].sprite = defaultBorder; player1Index.x = MoveX(player1Index.x, -1);; selectionGrid[player1Index.x, player1Index.y].sprite = playerOneHighlight; } canMoveP1 = false; timeNextMoveP1 = Time.time + buttonSelectDelay; } // Move up/down if (canMoveP1 && Mathf.Abs(XCI.GetAxisRaw(XboxAxis.LeftStickY, XboxController.First)) > 0.5f) { if (XCI.GetAxisRaw(XboxAxis.LeftStickY, XboxController.First) > 0.0f) { selectionGrid[player1Index.x, player1Index.y].sprite = defaultBorder; player1Index.y = MoveY(player1Index.y, -1); selectionGrid[player1Index.x, player1Index.y].sprite = playerOneHighlight; } else { selectionGrid[player1Index.x, player1Index.y].sprite = defaultBorder; player1Index.y = MoveY(player1Index.y, 1); selectionGrid[player1Index.x, player1Index.y].sprite = playerOneHighlight; } canMoveP1 = false; timeNextMoveP1 = Time.time + buttonSelectDelay; } if (!canMoveP1 && Time.time > timeNextMoveP1) { canMoveP1 = true; } if (XCI.GetButtonDown(XboxButton.A, XboxController.First)) { selectionGrid[player1Index.x, player1Index.y].sprite = lockedInBorder; player1Ready = true; } } // Player 2 if (!player2Ready) { // Move left/Right if (canMoveP2 && Mathf.Abs(XCI.GetAxisRaw(XboxAxis.LeftStickX, XboxController.Second)) > 0.5f) { if (XCI.GetAxisRaw(XboxAxis.LeftStickX, XboxController.Second) > 0.0f) { selectionGrid[player2Index.x, player2Index.y].sprite = defaultBorder; player2Index.x = MoveX(player2Index.x, 1); selectionGrid[player2Index.x, player2Index.y].sprite = playerTwoHighlight; } else { selectionGrid[player2Index.x, player2Index.y].sprite = defaultBorder; player2Index.x = MoveX(player2Index.x, -1);; selectionGrid[player2Index.x, player2Index.y].sprite = playerTwoHighlight; } canMoveP2 = false; timeNextMoveP2 = Time.time + buttonSelectDelay; } // Move up/down if (canMoveP2 && Mathf.Abs(XCI.GetAxisRaw(XboxAxis.LeftStickY, XboxController.Second)) > 0.5f) { if (XCI.GetAxisRaw(XboxAxis.LeftStickY, XboxController.Second) > 0.0f) { selectionGrid[player2Index.x, player2Index.y].sprite = defaultBorder; player2Index.y = MoveY(player2Index.y, -1); selectionGrid[player2Index.x, player2Index.y].sprite = playerTwoHighlight; } else { selectionGrid[player2Index.x, player2Index.y].sprite = defaultBorder; player2Index.y = MoveY(player2Index.y, 1); selectionGrid[player2Index.x, player2Index.y].sprite = playerTwoHighlight; } canMoveP2 = false; timeNextMoveP2 = Time.time + buttonSelectDelay; } if (XCI.GetButtonDown(XboxButton.A, XboxController.Second)) { selectionGrid[player2Index.x, player2Index.y].sprite = lockedInBorder; player2Ready = true; } if (!canMoveP2 && Time.time > timeNextMoveP2) { canMoveP2 = true; } } if (player1Ready && player2Ready) { buttons[2].color = selectedColour; if (XCI.GetButtonDown(XboxButton.A, XboxController.All)) { inSelectMenu = false; SceneManager.LoadScene(1); } } } }
// Update is called once per frame void Update() { // Quick start the game in debug mode. if (Input.GetKeyDown(toggleDebugMode.debugStartKey) && toggleDebugMode.startInDebugMode) { PlayerData.instance.DebugPlayerCount = toggleDebugMode.debugPlayerCount; PlayerData.instance.StartInDebugMode = true; this.canStart = true; } if (isAtConnectScreen) { if (connectedControllerList.Count > 0) { if (!canStart) { for (int c = 0; c < connectedControllerList.Count; ++c) { XboxController xboxController = connectedControllerList[c]; // If xbox controller is all then skip: if (xboxController == XboxController.All) { continue; } // Listening to avalible controllers that have yet to be connected: if (XCI.GetButtonUp(XboxButton.B, xboxController)) { this.RemoveController(xboxController); } // Listening to avalible controllers that have yet to be connected: if (XCI.GetButtonUp(XboxButton.A, xboxController)) { this.AddController(xboxController); } } } else { // Listening to avalible controllers that have yet to be connected: if (XCI.GetButtonUp(XboxButton.B, XboxController.All)) { canStart = false; gameStartTimer = maxGameStartTimer; gameStartText.text = startingGameInText + gameStartTimer.ToString("0.00"); } } // Checking if enough players are connected: if (assignedPlayers > 1) { PlayerData.instance.CurrentSplitScreenMode = ((PlayerData.SplitScreenMode)assignedPlayers - 1); //allControllersConnectedScreen.SetActive(true); if (XCI.GetButtonUp(XboxButton.Start, XboxController.All)) { this.canStart = true; } } } } // Checking if we can start the game: if (canStart) { if (toggleDebugMode.startInDebugMode) { StartGame(); } else { if (gameStartTimer <= maxGameStartTimer) { gameStartTimer -= Time.deltaTime; gameStartText.text = startingGameInText + gameStartTimer.ToString("0.00"); if (gameStartTimer <= 0f) { gameStartTimer = 0f; StartGame(); } } } } }