public void Update() { if (InputManager.ActiveDevice != device) { device = InputManager.ActiveDevice; } _x = device.GetControl(xcontrolType).Value; _y = device.GetControl(ycontrolType).Value; if (Mathf.Abs(_x) + Mathf.Abs(_y) < deadZone) { _x = 0; _y = 0; } _x *= sensitivity * sensitivity * Mathf.Abs(_x / sensitivity); _y *= sensitivity * sensitivity * Mathf.Abs(_y / sensitivity); if (invertX == true) { _x *= -1; } if (invertY == true) { _y *= -1; } _x /= (1f - deadZone); }
public void Fire(GameObject currGameObject, InputDevice player) { audioManager.PlaySound("shoot"); //StartCoroutine(ChillAsGhost(currGameObject, player)); BecomeGhost(currGameObject); Vector2 Temp = new Vector2(); InputControl aimX = player.GetControl(InputControlType.LeftStickX); InputControl aimY = player.GetControl(InputControlType.LeftStickY); Aim(currGameObject, player); //if (currGameObject.GetComponent<Character_Behavior2>() != null) // Temp = currGameObject.GetComponent<Character_Behavior2>().LastAim; //else //{ Temp = LastAim; //} //old code for regular bullets //GameObject shotcreate = Instantiate(shot); //ShotBehavior shotinit = shotcreate.GetComponent<ShotBehavior>(); //shotinit.Init(currGameObject, (Vector2)currGameObject.transform.position + (1.5F * (Temp)), Temp); //new code for boomerang bullets GameObject shotcreate = Instantiate(shot); //This might possibly spawn the boomerang inside Script_Boomerang_Bullet myBoomBulletScript = shotcreate.GetComponent <Script_Boomerang_Bullet>(); shotready = Time.time + shootdelay; //initilizes shot parameters myBoomBulletScript.shotInit(facingRight, gameObject); }
public bool Action1WasPressed() { bool isController = ControllerType == EControllerType.Controller; bool wasPressed = isController ? Device.GetControl(InputControlType.Action1).WasPressed : Input.GetKeyDown(Action1); return(wasPressed); }
public float GetSteering() { if (inputDevice == null) { return(0); } return(inputDevice.GetControl(InputControlType.LeftStickX).Value); }
void FixedUpdate() { InputDevice player = InputManager.Devices[playerNumber]; InputControl xControl = player.GetControl(InputControlType.LeftStickX); InputControl yControl = player.GetControl(InputControlType.LeftStickY); myAnim.SetFloat("XSpeed", Mathf.Abs(xControl.Value)); //Sets orientation of sprite if (xControl.Value > .01f || Input.GetKey(KeyCode.D)) { facingRight = true; } if (xControl.Value < -.01f || Input.GetKey(KeyCode.A)) { facingRight = false; } if (facingRight) { //Debug.Log(transform.rotation);// == new Quaternion (0, 180, 0, 0)) if (transform.rotation.y == -1) { transform.Rotate(0, -180, 0); } } //transform.localScale = new Vector2(1, transform.localScale.y); else if (!facingRight) { if (transform.rotation.y == 0) { transform.Rotate(0, 180, 0); } //Debug.Log(transform.rotation);// == new Quaternion (0, 180, 0, 0)) } // transform.localScale = new Vector2(-1, transform.localScale.y); FallingPhysics(mybody); //Dash Ability if (dash) { audioManager.PlaySound("dash"); Dash(xControl, myDashMove); dash = false; } //Might be important this stays at the end Move(xControl.Value, mybody, myDashMove); }
public Vector2 GetMovement() { var lpadX = inputDevice.GetControl(InputControlType.LeftStickX); var lpadY = inputDevice.GetControl(InputControlType.LeftStickY); if (lpadX.HasChanged || lpadY.HasChanged) { return(new Vector2(lpadX.Value, lpadY.Value)); } else { return(Vector2.zero); } }
// Update is called once per frame private void Update() { if (_unassignedPlayers == null || (_unassignedDevices == null && hasBoundKeyboard)) { return; } if (_unassignedPlayers.Count == 0 || (_unassignedDevices.Count == 0 && hasBoundKeyboard)) { return; } // Check Keyboard if (!hasBoundKeyboard) { if (Input.GetKeyUp(KeyCode.Space)) { // Assign to the next player PlayerController nextPlayer = _unassignedPlayers[0]; nextPlayer.BindKeyboard(); _unassignedPlayers.RemoveAt(0); _assignedPlayers.Add(nextPlayer); nextPlayer.gameObject.SetActive(true); hasBoundKeyboard = true; } } // Check Gamepad InputDevice activeDevice = InputManager.ActiveDevice; InputControl startButton = activeDevice.GetControl(InputControlType.Start); InputControl menuButton = activeDevice.GetControl(InputControlType.Menu); if (startButton.WasPressed || menuButton.WasPressed) { if (_unassignedDevices.Contains(activeDevice)) { // Assign to the next player _unassignedDevices.Remove(activeDevice); _assignedDevices.Add(activeDevice); PlayerController nextPlayer = _unassignedPlayers[0]; nextPlayer.BindGamepad(activeDevice); _unassignedPlayers.RemoveAt(0); _assignedPlayers.Add(nextPlayer); nextPlayer.gameObject.SetActive(true); } } }
void CheckForButtonPress() { if (IsNull(inputdev)) { return; } InputControl control = inputdev.GetControl(InputControlType.Action1); if (control.IsPressed) { if (this.name == "Player") { Debug.Log(this.name + ": Start Button pressed!"); string mode = GlobalState().GameMode(); if (GlobalState().InDemoMode() || mode == "GameOver") { GlobalState().GameStart(); } } else { // we are a baddy, button helps to figure out which one! highlightSprite = true; } } else { highlightSprite = false; } }
void FixedUpdate() { InputDevice player = InputManager.ActiveDevice; InputControl movecontrol = player.GetControl(InputControlType.LeftStickX); Move(movecontrol.Value); myAnim.SetFloat("moveSpeed", Mathf.Abs(movecontrol.Value)); if (movecontrol.Value > .01f) { transform.localScale = new Vector2(1, transform.localScale.y); } if (movecontrol.Value < -.01f) { transform.localScale = new Vector2(-1, transform.localScale.y); } //Now checks if the trigger is active if (player.Action2 && myTrigger.GetIsActive()) { Jump(); myTrigger.BeatHit(); } //Dash Ability if (player.Action3 && myTrigger.GetIsActive()) { //negative on the y to invert stick for some reason Dash(Input.GetAxisRaw("L_XAxis_1"), -Input.GetAxisRaw("L_YAxis_1")); myTrigger.BeatHit(); } //Alt jump for testing if (Input.GetKeyDown(KeyCode.D) && myTrigger.GetIsActive()) { Jump(); myTrigger.BeatHit(); } //Alt dash for testing if (Input.GetKeyDown(KeyCode.S) && myTrigger.GetIsActive()) { Dash(1, 1); myTrigger.BeatHit(); } // player is falling if (mybody.velocity.y < 0) { mybody.velocity += Vector2.up * Physics2D.gravity.y * (fallMultiplier - 1) * Time.deltaTime; // minus 1 because unity is already applying 1 multiple of the gravity (don't want to add gravity part twice) } // player is moving up in the jump and a is released else if (mybody.velocity.y > 0) //&& !Input.GetButton("A_1")) { mybody.velocity += Vector2.up * Physics2D.gravity.y * (lowJumpMultiplier - 1) * Time.deltaTime; } }
private bool WasPressed(InputDevice device, InputControlType type) { if (device != null) { return(device.GetControl(type).WasPressed); } return(false); }
public override void Process() { for (var i = 0; i < _pointers.Count; i++) { PlayerPointer pointer = _pointers[i]; Player player = pointer.Player; InputDevice controller = player.Controller; if (controller == null) { continue; } // Move the controller pointer.Move(new Vector2(controller.GetControl(_horizontal), controller.GetControl(_vertical))); ProcessPointerSubmit(pointer, i, controller); CharacterChange(pointer, player, controller); } }
private void Update() { if (inputDevice.GetControl(PlayerActions.PAUSE).WasPressed) { MatchManager.instance.PauseGame(playerID); } ccManager.Update(); }
public bool GetActionPressed() { if (myInputDevice != null) { return(myInputDevice.GetControl(InputControlType.Action1)); } return(Input.GetKey(KeyCode.Return)); }
void Update() { if (onTrigger) { if (inputDevice.GetControl(InputControlType.Action2) && grabNextInput) { if (!steeringMode && !myBoat.GetComponent <BoatSteering>().GetSteeringMode()) { //put the player in steering mode SetPlayerSteeringMode(false); transform.position = wheel.transform.position + Vector3.up * 1.5f + -wheel.transform.forward.normalized; transform.rotation = wheel.transform.rotation; //myBoat is now in steering mode myBoat.GetComponent <BoatSteering>().SetSteeringMode(true, inputDevice); grabNextInput = false; StartCoroutine(WaitBetweenInputs()); } } if (inputDevice.GetControl(InputControlType.Action2) && grabNextInput) { if (steeringMode && myBoat.GetComponent <BoatSteering>().GetSteeringMode()) { //take the player out of steering mode SetPlayerSteeringMode(true); //myBoat out of steering mode myBoat.GetComponent <BoatSteering>().SetSteeringMode(false); grabNextInput = false; StartCoroutine(WaitBetweenInputs()); } } } if (steeringMode) { rb.constraints = RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotation; } else { rb.constraints = RigidbodyConstraints.FreezeRotation; } }
private float GetAxis(InputDevice device, InputControlType type) { if (device != null) { return(device.GetControl(type).Value); } return(0f); }
private InputDevice CheckForControllerCancel(InputDevice controller) { if (controller != null && controller.GetControl(InputControlType.Action2).WasPressed) { return(null); } return(controller); }
public static bool GetInput(InputControlType input, TimeType timeType) { InputDevice device = InputManager.ActiveDevice; switch (timeType) { case TimeType.UP: return(device.GetControl(input).WasReleased); case TimeType.DOWN: return(device.GetControl(input).WasPressed); case TimeType.ALWAYS: return(device.GetControl(input).IsPressed); } return(false); }
private float GetAxisPress(InputDevice device, InputControlType type) { if (device != null) { InputControl control = device.GetControl(type); return(control.WasPressed ? control.Value : 0f); } return(0f); }
public override bool GetState(InputDevice inputDevice) { if (inputDevice == null) { return(false); } return(inputDevice.GetControl(Control).State); }
public override float GetValue(InputDevice inputDevice) { if (inputDevice == null) { return(0.0f); } return(inputDevice.GetControl(Control).Value); }
void CharacterChange(PlayerPointer pointer, Player player, InputDevice controller) { if (!player.SelectedCharacter) { return; } if (controller.GetControl(_changeLeft).WasPressed) { player.Pallete--; } if (controller.GetControl(_changeRight).WasPressed) { player.Pallete++; } if (controller.GetControl(_cancel).WasPressed) { } }
private float GetAxisThreshold(InputDevice device, InputControlType type) { if (device != null) { InputControl control = device.GetControl(type); return(Mathf.Abs(control.LastValue) < 0.5f && Mathf.Abs(control.Value) >= 0.5f ? Mathf.Sign(control.Value) : 0f); } return(0f); }
public void Dash(InputControl xControl, Script_DashMove myDashMove) { //camera shake function CameraShaker.Instance.ShakeOnce(5f, 3f, 0f, .5f); InputControl aimX = player.GetControl(InputControlType.LeftStickX); InputControl aimY = player.GetControl(InputControlType.LeftStickY); float Y = aimY.Value; float X = aimX.Value; float YAbsVal = Mathf.Abs(Y); float XAbsVal = Mathf.Abs(X); if (X < 0 && XAbsVal > YAbsVal) { myDashMove.direction = 1; } else if (X > 0 && XAbsVal > YAbsVal) { myDashMove.direction = 2; } else if (Y > 0 && YAbsVal > XAbsVal) { myDashMove.direction = 3; } else if (Y < 0 && YAbsVal > XAbsVal) { myDashMove.direction = 4; } else if (xControl.Value == 0) { if (facingRight) { myDashMove.direction = 2; } if (!facingRight) { myDashMove.direction = 1; } } //Needs to go at end because this depends on the myDashMove.direction value StartCoroutine("dashFlash"); }
// Update is called once per frame void Update() { input = InputManager.ActiveDevice; if (input.GetControl(InputControlType.Start)) { print("YOYO"); GameObject.FindGameObjectWithTag("SceneTransition").GetComponent <SceneTransition>().QueueSceneTransition(sceneToLoad); } }
// Update is called once per frame void Update() { InputDevice device = InputManager.ActiveDevice; InputControl control = device.GetControl(InputControlType.RightTrigger); if ((Input.GetKey(KeyCode.Space) || control.IsPressed) && !shooting && GetComponent <SpriteRenderer>().color != Color.white) { StartCoroutine(shootBullet()); } }
void Update() { InputDevice device = InputManager.ActiveDevice; // Movement float n = device.GetControl(InputControlType.LeftStickY).Value + device.GetControl(InputControlType.RightStickY).Value + Input.GetAxis("Vertical"); float e = device.GetControl(InputControlType.LeftStickX).Value + device.GetControl(InputControlType.RightStickX).Value + Input.GetAxis("Horizontal"); bool l = device.GetControl(InputControlType.Action1).State || device.GetControl(InputControlType.Action2).State || device.GetControl(InputControlType.RightTrigger).State || device.GetControl(InputControlType.RightBumper).State || Input.GetButton("Jump"); Vector3 dir = Vector3.zero; if ((Mathf.Abs(e) > dead || Mathf.Abs(n) > dead)) { dir = new Vector3(e, 0, n); if (!l) { angle = Vector3.Angle(Vector3.forward, dir.normalized); if (e < 0) { angle = 360 - angle; } } else { angle = transform.eulerAngles.y; } diff = Vector3.Angle(transform.eulerAngles, dir.normalized); //transform.eulerAngles = ea; } Vector3 ea = transform.eulerAngles; // Rate is 0.1s per 180 degrees ea.y = Mathf.SmoothDampAngle(ea.y, angle, ref rRate, rSmooth * diff / 180); Quaternion q = Quaternion.Euler(ea); rb.rotation = q; rb.velocity = Vector3.SmoothDamp(rb.velocity, Vector3.ClampMagnitude(dir, 1) * speed * (l?lockFactor:1), ref moveRate, drag); Vector3 camPos = Vector3.SmoothDamp(cam.position, transform.position, ref camRate, camLag); camPos.y = cam.position.y; cam.position = camPos; }
bool AnyButtonPressed(InputControlType[] targetSet, InputDevice device) { for (int i = 0; i < targetSet.Length; i++) { if (device.GetControl(targetSet[i])) { return(true); } } return(false); }
public override void OnUpdate() { bool buttonUp = !_inputDevice.GetControl(axis).IsPressed; if (buttonUp) { Fsm.Event(sendEvent); } storeResult.Value = buttonUp; }
// Update is called once per frame void Update() { input = InputManager.ActiveDevice; if (input.GetControl(InputControlType.Start)) { Destroy(GameObject.Find("OST Theme Tutorial")); Destroy(GameObject.Find("PressStartToSkipCanvas")); GameObject.FindGameObjectWithTag("SceneTransition").GetComponent <SceneTransition>().QueueSceneTransition(sceneToLoad); Destroy(gameObject); } }
/// <summary> /// Fires the input events for keyboard/touch/controller, takes in the current active device from InControl /// </summary> /// <param name="inputDevice">The current Active Device in the System</param> public void FireInputEvents(InputDevice inputDevice) { if (Input.GetKeyDown(key) || //Check for keyboard key pressed down inputDevice.GetControl(touch).WasPressed || //Check for touch control pressed down inputDevice.GetControl(button).WasPressed) //Check for Controller button pressed down { //if any of the input has been pressed down we fire the event if (OnInputDown != null) { OnInputDown(); } } if (Input.GetKey(key) || //Check for keyboard key press inputDevice.GetControl(touch).HasInput || //Check for touch control press inputDevice.GetControl(button).HasInput) //Check for touch control press { //if any of the input has been pressed down we fire the event if (OnInput != null) { OnInput(); } } if (Input.GetKeyUp(key) || //Check for keyboard key release inputDevice.GetControl(touch).WasReleased || //Check for touch control release inputDevice.GetControl(button).WasReleased) //Check for Controller button release { //if any of the input has been pressed down we fire the event if (OnInputUp != null) { OnInputUp(); } } }