/* * A = 0, * B = 1, * X = 2, * Y = 3, * * DPad_UP = 4, * DPad_DOWN = 5, * DPad_LEFT = 6, * DPad_RIGHT = 7, * * Shldr_LEFT = 8, * Shldr_RIGHT = 9, * * ThumbStick_LEFT = 10, * ThumbStick_RIGHT = 11, * * Start = 12, * Back = 13 */ // Update is called once per frame void Update() { if (!isKeyboard) { if (manager.state.state == 0) { commands.jump = GamePadManager.GetControllerKeyPressed(manager.playerGamepad.gamepad, 0); commands.flip = GamePadManager.GetControllerKeyDown(manager.playerGamepad.gamepad, 8); commands.aim = GamePadManager.GetControllerAxes(manager.playerGamepad.gamepad).l_Trigger > 0.4f; commands.shoot = GamePadManager.GetControllerAxes(manager.playerGamepad.gamepad).r_Trigger > 0.4f; commands.sprint = GamePadManager.GetControllerKeyDown(manager.playerGamepad.gamepad, 10); commands.slam = GamePadManager.GetControllerKeyPressed(manager.playerGamepad.gamepad, 2); commands.dash = GamePadManager.GetControllerKeyPressed(manager.playerGamepad.gamepad, 11); commands.swap = GamePadManager.GetControllerKeyPressed(manager.playerGamepad.gamepad, 3); commands.crouch = GamePadManager.GetControllerKeyPressed(manager.playerGamepad.gamepad, 1); //commands.grenade = GamePadManager.GetControllerKeyPressed(manager.playerGamepad.gamepad, 9); } commands.pause = GamePadManager.GetControllerKeyPressed(manager.playerGamepad.gamepad, 12); commands.menuUp = GamePadManager.GetControllerKeyPressed(manager.playerGamepad.gamepad, 4); commands.menuDown = GamePadManager.GetControllerKeyPressed(manager.playerGamepad.gamepad, 5); commands.menuLeft = GamePadManager.GetControllerKeyPressed(manager.playerGamepad.gamepad, 6); commands.menuRight = GamePadManager.GetControllerKeyPressed(manager.playerGamepad.gamepad, 7); commands.back = GamePadManager.GetControllerKeyPressed(manager.playerGamepad.player, 1); commands.select = GamePadManager.GetControllerKeyPressed(manager.playerGamepad.player, 0); } else { if (manager.state.state == 0) { commands.jump = Input.GetKeyDown(KeyCode.Space); commands.flip = Input.GetKeyDown("q"); commands.aim = Input.GetMouseButton(1); commands.shoot = Input.GetMouseButton(0); commands.sprint = Input.GetKeyDown(KeyCode.LeftShift); commands.slam = Input.GetKeyDown(KeyCode.LeftControl); commands.dash = Input.GetKeyDown(KeyCode.E); } commands.pause = Input.GetKeyDown(KeyCode.Escape); commands.menuUp = Input.GetKeyDown(KeyCode.W); commands.menuDown = Input.GetKeyDown(KeyCode.S); commands.menuLeft = Input.GetKeyDown(KeyCode.A); commands.menuRight = Input.GetKeyDown(KeyCode.D); commands.back = Input.GetKeyDown(KeyCode.Escape); commands.select = Input.GetKeyDown(KeyCode.Return); } }
// Update is called once per frame void Update() { if (!manager.playerGamepad.isKeyboard) { rawRight = new Vector2(GamePadManager.GetControllerAxes(manager.playerGamepad.player).r_ThumbStick_X, GamePadManager.GetControllerAxes(manager.playerGamepad.player).r_ThumbStick_Y); adjustedRight = Vector2.Lerp(adjustedRight, rawRight, lerpSpeed * Time.deltaTime * 10); rawLeft = new Vector2(GamePadManager.GetControllerAxes(manager.playerGamepad.player).l_ThumbStick_X, GamePadManager.GetControllerAxes(manager.playerGamepad.player).l_ThumbStick_Y); adjustedLeft = Vector2.Lerp(adjustedLeft, rawLeft, lerpSpeed * Time.deltaTime * 10); } if (Vector2.SqrMagnitude(rawRight) < 0.1) { adjustedRight = Vector2.zero; } if (Vector2.SqrMagnitude(rawLeft) < 0.1) { adjustedLeft = Vector2.zero; } }
void Update() { if (Input.GetKeyDown("k")) { manager.target.health = 0; } dashtimer -= Time.deltaTime; dash = false; speed = baseSpeed * 1000; if (manager.playerGamepad.commands.aim) { speed *= adsMod; } if (manager.playerGamepad.commands.sprint) { sprint = true; } if (onGround) { slam = false; } else if (manager.playerGamepad.commands.slam) { slam = true; } if (manager.playerGamepad.commands.dash && dashtimer < 0) { if (!manager.playerGamepad.isKeyboard) { rb.AddForce((transform.forward * stickVelocity.y) * speed / 50 * dashMod); rb.AddForce((transform.right * stickVelocity.x) * speed / 50 * dashMod); } else { if (Input.GetKey("w")) { rb.AddForce(transform.forward * speed / 50 * dashMod); } if (Input.GetKey("s")) { rb.AddForce(-transform.forward * speed / 50 * dashMod); } if (Input.GetKey("a")) { rb.AddForce(-transform.right * speed / 50 * dashMod); } if (Input.GetKey("d")) { rb.AddForce(transform.right * speed / 50 * dashMod); } } dashtimer = dashcoolDown; } else if (manager.playerGamepad.isKeyboard && !Input.GetKey("w")) { sprint = false; } else if (!manager.playerGamepad.isKeyboard && GamePadManager.GetControllerAxes(manager.playerGamepad.player).r_ThumbStick_Y < 0.4) { sprint = false; } rayHit = Physics.Raycast(manager.cam.transform.position, manager.cam.transform.forward, out rayOutData, 1000.0f, manager.cam.GetComponent <Camera>().cullingMask); if (onGround) { rb.drag = 5; } else { rb.drag = 0.5f; } aimAssist.x = 0; if (!manager.playerGamepad.isKeyboard) { stickVelocity = new Vector2(GamePadManager.GetControllerAxes(manager.playerGamepad.gamepad).l_ThumbStick_X, GamePadManager.GetControllerAxes(manager.playerGamepad.gamepad).l_ThumbStick_Y); if (stickVelocity.sqrMagnitude < 0.1) { stickVelocity = Vector2.zero; } if (manager.movment.rayHit) { if (manager.movment.rayOutData.transform.name == "hitBox") { if ((stickVelocity.x * 1 / rayOutData.distance) * 10 > 0 && Aim_Assist.AngleDir(transform.forward, rayOutData.transform.position - transform.position, transform.up) < 0) { aimAssist.x = -((stickVelocity.x * 1 / rayOutData.distance) * 10);// * manager.gunBehavior.currentGun.aimAssist; } if ((stickVelocity.x * 1 / rayOutData.distance) * 10 < 0 && Aim_Assist.AngleDir(transform.forward, rayOutData.transform.position - transform.position, transform.up) > 0) { aimAssist.x = -((stickVelocity.x * 1 / rayOutData.distance) * 10);// * manager.gunBehavior.currentGun.aimAssist; } } } } //zero_g glitch would need to be fixed possibly replaced with Low gravity mode if (Input.GetKeyDown("e")) { //gravity = false; } if (gravity) { airmod = 4; if (!onGround && !slam) { rb.AddForce(-cameraTargetUp * 75); } else if (!onGround && slam) { rb.AddForce(-cameraTargetUp * 75 * 5); } } else { airmod = 50; } //Walking around if (onGround) { if (!manager.playerGamepad.isKeyboard) { if (stickVelocity.y > 0) { if (sprint) { rb.AddForce(transform.forward * speed * sprintMod * Time.deltaTime * stickVelocity.y); } else { rb.AddForce(transform.forward * speed * Time.deltaTime * stickVelocity.y); } runningAnimation = true; } else { rb.AddForce(transform.forward * speed * backupMod * Time.deltaTime * stickVelocity.y); runningAnimation = false; } rb.AddForce(transform.right * speed * strafeMod * Time.deltaTime * stickVelocity.x); } else { if (Input.GetKey("w")) { if (sprint) { rb.AddForce(transform.forward * speed * sprintMod * Time.deltaTime); } else { rb.AddForce(transform.forward * speed * Time.deltaTime); } runningAnimation = true; } if (Input.GetKey("s")) { rb.AddForce(-transform.forward * speed * backupMod * Time.deltaTime); runningAnimation = true; } if (Input.GetKey("a")) { rb.AddForce(-transform.right * speed * strafeMod * Time.deltaTime); runningAnimation = true; } if (Input.GetKey("d")) { rb.AddForce(transform.right * speed * strafeMod * Time.deltaTime); runningAnimation = true; } if (Input.GetKeyUp("w") && Input.GetKeyUp("s") && Input.GetKeyUp("a") && Input.GetKeyUp("d")) { runningAnimation = false; } } } if (!onGround && !slam) { if (!manager.playerGamepad.isKeyboard) { rb.AddForce(transform.forward / airmod * speed * Time.deltaTime * stickVelocity.y); rb.AddForce(transform.right / airmod * speed * Time.deltaTime * stickVelocity.x); } else { if (Input.GetKey("w")) { rb.AddForce(transform.forward / airmod * speed * Time.deltaTime); } if (Input.GetKey("s")) { rb.AddForce(-transform.forward / airmod * speed * Time.deltaTime); } if (Input.GetKey("a")) { rb.AddForce(-transform.right / airmod * speed * Time.deltaTime); } if (Input.GetKey("d")) { rb.AddForce(transform.right / airmod * speed * Time.deltaTime); } } } //jumping if ((manager.playerGamepad.commands.jump && onGround)) { jumping = true; rb.AddForce(transform.up * 2000); } else { jumping = false; } cameraFlip(); //print(rb.velocity.magnitude); /*FOR NETWORKING*/ //animation //if (onGround && rb.velocity.magnitude >= 2.0f) //{ // runningAnimation = true; //} //else if (!onGround || rb.velocity.magnitude < 2.0f) //{ // runningAnimation = false; //} if (!gravity) { transform.forward = manager.cam.transform.forward; } onGround = false; //Debug.DrawLine(transform.position, transform.position + cameraLerpUp * 10, Color.red); }
// Update is called once per frame void Update() { if (MenuStates.menuState == 0) { currentHeight = menuHeight; currentMax = menuButtons.Length; cursor.transform.position = menuButtons[slot].transform.position; cursor.GetComponent <CursorSizeing>().bottomDistance.x = menuButtons[slot].GetComponent <RectTransform>().sizeDelta.x * 0.5f; cursor.GetComponent <CursorSizeing>().bottomDistance.y = -menuButtons[slot].GetComponent <RectTransform>().sizeDelta.y * 0.5f; cursor.GetComponent <CursorSizeing>().topDistance.x = -menuButtons[slot].GetComponent <RectTransform>().sizeDelta.x * 0.5f; cursor.GetComponent <CursorSizeing>().topDistance.y = menuButtons[slot].GetComponent <RectTransform>().sizeDelta.y * 0.5f; } if (MenuStates.menuState == 1) { if (slot == 1) { temp = GameObject.Find("Map1").GetComponent <Image>().color; temp.a = 0.0f; GameObject.Find("Map1").GetComponent <Image>().color = temp; temp = GameObject.Find("Map2").GetComponent <Image>().color; temp.a = 1.0f; GameObject.Find("Map2").GetComponent <Image>().color = temp; temp = GameObject.Find("Map3").GetComponent <Image>().color; temp.a = 1.0f; GameObject.Find("Map3").GetComponent <Image>().color = temp; } else if (slot == 2) { temp = GameObject.Find("Map2").GetComponent <Image>().color; temp.a = 0.0f; GameObject.Find("Map2").GetComponent <Image>().color = temp; temp = GameObject.Find("Map1").GetComponent <Image>().color; temp.a = 1.0f; GameObject.Find("Map1").GetComponent <Image>().color = temp; temp = GameObject.Find("Map3").GetComponent <Image>().color; temp.a = 1.0f; GameObject.Find("Map3").GetComponent <Image>().color = temp; } else if (slot == 3) { temp = GameObject.Find("Map3").GetComponent <Image>().color; temp.a = 0.0f; GameObject.Find("Map3").GetComponent <Image>().color = temp; temp = GameObject.Find("Map2").GetComponent <Image>().color; temp.a = 1.0f; GameObject.Find("Map2").GetComponent <Image>().color = temp; temp = GameObject.Find("Map1").GetComponent <Image>().color; temp.a = 1.0f; GameObject.Find("Map1").GetComponent <Image>().color = temp; } else { temp = GameObject.Find("Map1").GetComponent <Image>().color; temp.a = 1.0f; GameObject.Find("Map1").GetComponent <Image>().color = temp; temp = GameObject.Find("Map2").GetComponent <Image>().color; temp.a = 1.0f; GameObject.Find("Map2").GetComponent <Image>().color = temp; temp = GameObject.Find("Map3").GetComponent <Image>().color; temp.a = 1.0f; GameObject.Find("Map3").GetComponent <Image>().color = temp; } currentHeight = localHeight; currentMax = localButtons.Length; cursor.transform.position = localButtons[slot].transform.position; cursor.GetComponent <CursorSizeing>().bottomDistance.x = localButtons[slot].GetComponent <RectTransform>().sizeDelta.x * 0.5f; cursor.GetComponent <CursorSizeing>().bottomDistance.y = -localButtons[slot].GetComponent <RectTransform>().sizeDelta.y * 0.5f; cursor.GetComponent <CursorSizeing>().topDistance.x = -localButtons[slot].GetComponent <RectTransform>().sizeDelta.x * 0.5f; cursor.GetComponent <CursorSizeing>().topDistance.y = localButtons[slot].GetComponent <RectTransform>().sizeDelta.y * 0.5f; } for (int i = 0; i <= 3; i++) { m_ctrlrTimer[i] -= Time.deltaTime; m_InputAxes[i] = GamePadManager.GetControllerAxes(i); if (GamePadManager.GetControllerKeyPressed(i, 5) || (m_InputAxes[i].l_ThumbStick_Y <= -0.3f && m_ctrlrTimer[i] <= 0f)) { Debug.Log("down"); m_ctrlrTimer[i] = 0.15f; if (slot < currentMax - 1 && (slot + 1) % currentHeight != 0) { slot++; } } else if (GamePadManager.GetControllerKeyPressed(i, 4) || (m_InputAxes[i].l_ThumbStick_Y >= 0.3f && m_ctrlrTimer[i] <= 0f)) { Debug.Log("up"); m_ctrlrTimer[i] = 0.15f; if (slot > 0 && (slot) % currentHeight != 0) { slot--; } } else if (GamePadManager.GetControllerKeyPressed(i, 6) || (m_InputAxes[i].l_ThumbStick_X <= -0.3f && m_ctrlrTimer[i] <= 0f)) { Debug.Log("left"); m_ctrlrTimer[i] = 0.15f; if (slot - (currentHeight - 1) > 0) { slot -= currentHeight; } } else if (GamePadManager.GetControllerKeyPressed(i, 7) || (m_InputAxes[i].l_ThumbStick_Y >= 0.3f && m_ctrlrTimer[i] <= 0f)) { Debug.Log("Right"); m_ctrlrTimer[i] = 0.15f; if (slot + currentHeight <= currentMax - 1) { slot += currentHeight; } } if (GamePadManager.GetControllerKeyPressed(i, 0)) { if (MenuStates.menuState == 0) { if (slot == 0) { MenuStates.menuState = 1; slot = 1; } else if (slot == 1) { MenuStates.menuState = 0; } else if (slot == 2) { //MenuStates.menuState = 2; } else if (slot == 3) { print("Close"); Application.Quit(); } } else if (MenuStates.menuState == 1) { if (slot == 0) { MenuStates.menuState = 0; } if (GamePadManager.playersActive > 0) { if (slot == 1) { localButtons[1].GetComponent <LoadLevel>().LoadMap1(); } else if (slot == 2) { localButtons[2].GetComponent <LoadLevel>().LoadMap2(); } else if (slot == 3) { localButtons[3].GetComponent <LoadLevel>().LoadMap4(); } } else { Instantiate <GameObject>(invalidSound); } if (slot == 4) { gameObject.GetComponent <MenuStates>().setGunGame(); } } } } }