// Update is called once per frame void Update() { playerIcon.GetComponent <Image>().sprite = playerRoles.helmets[(int)playerID]; #region tank top rotation float newRotation = tankTop.transform.parent.transform.localEulerAngles.y; float test = oldRotation - newRotation; tankTop.transform.Rotate(0f, test, 0f); if (InputManager.GetAxis("Right Stick Horizontal", playerID) != 0.0f) { tankTop.transform.Rotate(0f, (InputManager.GetAxis("Right Stick Horizontal", playerID) * gunnerRotateSpeed), 0f); } oldRotation = tankTop.transform.parent.transform.localEulerAngles.y; #endregion #region cannon angle //point cannon up if (InputManager.GetAxis("Left Stick Vertical", playerID) < 0) { if (angleCurrent < 100) { cannon.transform.RotateAround(cannonPivot.transform.position, cannonPivot.transform.right, -10 * Time.deltaTime); angleCurrent++; } } //point cannon down if (InputManager.GetAxis("Left Stick Vertical", playerID) > 0) { if (angleCurrent > -80) { cannon.transform.RotateAround(cannonPivot.transform.position, cannonPivot.transform.right, 10 * Time.deltaTime); angleCurrent--; } } #endregion #region main gun if (!reloading) { if (InputManager.GetAxis("Right Trigger", playerID) == 1) { // ToDo: ammotype needs to be implemented rockets.FireProjectile(selectedAmmo); reloading = true; playerRoles.DisplayPanel(anim, reloadPanel); launcher.GetComponent <LineRenderer>().enabled = false; } } else if (reloading) { activeReload.value += reloadSpeed; if (InputManager.GetAxis("Left Trigger", playerID) > 0 && !attemptedReload) { if (activeReload.value >= 0.45f && activeReload.value <= 0.55f) { activeReload.value = 0; reloading = false; playerRoles.HidePanel(anim, reloadPanel); launcher.GetComponent <LineRenderer>().enabled = true; } else { attemptedReload = true; } } if (activeReload.value >= 1) // adding half the width of line rail should make this dynamic { activeReload.value = 0;; reloading = false; attemptedReload = false; playerRoles.HidePanel(anim, reloadPanel); launcher.GetComponent <LineRenderer>().enabled = true; } } #endregion #region weapon swapping if (InputManager.GetButtonDown("Left Bumper", playerID)) { // display the options when pushing left bumper playerRoles.DisplayPanel(anim, ammoPanel); currentCombo = new List <string>(); } else if (InputManager.GetButtonUp("Left Bumper", playerID) || currentCombo.Count == 4) { if (currentCombo.Count == 4) { selectedAmmo = playerRoles.SelectAmmo(currentCombo, ammoCombos); abilityIcon.GetComponent <Image>().sprite = abilityIcons[selectedAmmo]; currentCombo = new List <string>(); } // display the options when pushing left bumper playerRoles.HidePanel(anim, ammoPanel); playerRoles.ResetCombo(comboButtons); } if (InputManager.GetButton("Left Bumper", playerID)) { // Add buttons to the current combo if (InputManager.GetButtonDown("Button A", playerID)) { currentCombo.Add("Button A"); playerRoles.DisplayCombo(currentCombo, comboButtons); } else if (InputManager.GetButtonDown("Button B", playerID)) { currentCombo.Add("Button B"); playerRoles.DisplayCombo(currentCombo, comboButtons); } else if (InputManager.GetButtonDown("Button X", playerID)) { currentCombo.Add("Button X"); playerRoles.DisplayCombo(currentCombo, comboButtons); } else if (InputManager.GetButtonDown("Button Y", playerID)) { currentCombo.Add("Button Y"); playerRoles.DisplayCombo(currentCombo, comboButtons); } } #endregion if (InputManager.GetAxis("DPAD Horizontal", playerID) == 1) { playerRoles.SwapToEngineer(this); } else if (InputManager.GetAxis("DPAD Vertical", playerID) == -1) { playerRoles.SwapToDriver(this); } else if (InputManager.GetAxis("DPAD Horizontal", playerID) == -1) { playerRoles.SwapToCommander(this); } }
// Update is called once per frame void Update() { if (playerID != playerRoles.gunner) { return; } #region tank top rotation float newRotation = tankTop.transform.parent.transform.localEulerAngles.y; float test = oldRotation - newRotation; tankTop.transform.Rotate(0f, test, 0f); if (InputManager.GetAxis("Right Stick Horizontal", playerID) != 0.0f) { tankTop.transform.Rotate(0f, (InputManager.GetAxis("Right Stick Horizontal", playerID) * gunnerRotateSpeed), 0f); } oldRotation = tankTop.transform.parent.transform.localEulerAngles.y; #endregion #region cannon angle //point cannon up if (InputManager.GetAxis("Left Stick Vertical", playerID) < 0) { if (angleCurrent < 100) { cannon.transform.RotateAround(cannonPivot.transform.position, cannonPivot.transform.right, -10 * Time.deltaTime); angleCurrent++; } } //point cannon down if (InputManager.GetAxis("Left Stick Vertical", playerID) > 0) { if (angleCurrent > -80) { cannon.transform.RotateAround(cannonPivot.transform.position, cannonPivot.transform.right, 10 * Time.deltaTime); angleCurrent--; } } #endregion #region main gun if (!reloading) { // draw line // ToDo: this should be a raycast to help see what it is aiming at Vector3 forward = launcher.transform.TransformDirection(Vector3.forward) * 20; Debug.DrawRay(launcher.transform.position, forward, Color.red); if (InputManager.GetAxis("Right Trigger", playerID) == 1) { // ToDo: ammotype needs to be implemented rockets.FireProjectile(selectedAmmo); reloading = true; playerRoles.DisplayPanel(anim, reloadPanel); } } else if (reloading) { marker.transform.Translate(Vector3.right * Time.deltaTime * reloadSpeed); if (InputManager.GetAxis("Left Trigger", playerID) > 0 && !attemptedReload) { if (marker.transform.position.x < sweetSpot.transform.position.x + 20.0f - 10 && marker.transform.position.x + 7.0f > sweetSpot.transform.position.x) { marker.transform.position = initialPos; reloading = false; playerRoles.HidePanel(anim, reloadPanel); } else { attemptedReload = true; reloadSpeed = 25; } } if (marker.transform.position.x >= (lineRail.transform.position.x + 109)) // adding half the width of line rail should make this dynamic { marker.transform.position = initialPos; reloading = false; attemptedReload = false; reloadSpeed = 50; playerRoles.HidePanel(anim, reloadPanel); } } #endregion #region weapon swapping if (InputManager.GetButtonDown("Left Bumper", playerID)) { // display the options when pushing left bumper playerRoles.DisplayPanel(anim, ammoPanel); currentCombo = new List <string>(); } else if (InputManager.GetButtonUp("Left Bumper", playerID) || currentCombo.Count == 4) { if (currentCombo.Count == 4) { selectedAmmo = playerRoles.SelectAmmo(currentCombo, ammoCombos); currentCombo = new List <string>(); } // display the options when pushing left bumper playerRoles.HidePanel(anim, ammoPanel); playerRoles.ResetCombo(comboButtons); } if (InputManager.GetButton("Left Bumper", playerID)) { // Add buttons to the current combo if (InputManager.GetButtonDown("Button A", playerID)) { currentCombo.Add("Button A"); playerRoles.DisplayCombo(currentCombo, comboButtons); } else if (InputManager.GetButtonDown("Button B", playerID)) { currentCombo.Add("Button B"); playerRoles.DisplayCombo(currentCombo, comboButtons); } else if (InputManager.GetButtonDown("Button X", playerID)) { currentCombo.Add("Button X"); playerRoles.DisplayCombo(currentCombo, comboButtons); } else if (InputManager.GetButtonDown("Button Y", playerID)) { currentCombo.Add("Button Y"); playerRoles.DisplayCombo(currentCombo, comboButtons); } } #endregion if (InputManager.GetAxis("DPAD Horizontal", playerID) == 1) { playerRoles.SwapToEngineer(this); } else if (InputManager.GetAxis("DPAD Vertical", playerID) == -1) { playerRoles.SwapToDriver(this); } else if (InputManager.GetAxis("DPAD Horizontal", playerID) == -1) { playerRoles.SwapToCommander(this); } }