major fixes, updated with vertical aiming, updated with menu to change sensitivity
This commit is contained in:
43
Assets/Scripts/Game/InGameMenuManager.cs
Normal file
43
Assets/Scripts/Game/InGameMenuManager.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class InGameMenuManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Button settingsButton;
|
||||
[SerializeField]
|
||||
private Button returnToMenuButton;
|
||||
private Animator menuAnimator;
|
||||
[SerializeField]
|
||||
private Scrollbar sensitivitySlider;
|
||||
private PlayerComponent player;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
menuAnimator= GetComponent<Animator>();
|
||||
settingsButton.onClick.AddListener(SettingsClicked);
|
||||
returnToMenuButton.onClick.AddListener(SettingsUnClicked);
|
||||
player = GameObject.FindObjectOfType(typeof(PlayerComponent)) as PlayerComponent;
|
||||
}
|
||||
void SettingsClicked()
|
||||
{
|
||||
menuAnimator.SetBool("SettingsOpen", true);
|
||||
}
|
||||
void SettingsUnClicked()
|
||||
{
|
||||
menuAnimator.SetBool("SettingsOpen", false);
|
||||
}
|
||||
public void UpdateSensitivity()
|
||||
{
|
||||
this.player.SetSensitivity(sensitivitySlider.value);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
11
Assets/Scripts/Game/InGameMenuManager.cs.meta
Normal file
11
Assets/Scripts/Game/InGameMenuManager.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 557d1d026294ceb4eb459580401a637c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -26,9 +26,10 @@ public class CameraController : MonoBehaviour
|
||||
private float newDist = 0;
|
||||
[SerializeField]
|
||||
private bool isChild = false;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
|
57
Assets/Scripts/Player/CameraShift.cs
Normal file
57
Assets/Scripts/Player/CameraShift.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Cinemachine;
|
||||
|
||||
public class CameraShift : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Camera childCam;
|
||||
[SerializeField]
|
||||
private Transform offset;
|
||||
private bool isCenter = true;
|
||||
private Vector3 targetOffset;
|
||||
[SerializeField]
|
||||
private float cameraSpeed = 5f;
|
||||
[SerializeField]
|
||||
private CinemachineFreeLook freelook;
|
||||
private float initRadius = 3f;
|
||||
private float aimingRadius = 2f;
|
||||
//[SerializeField]
|
||||
//private PlayerMovementController movementController;
|
||||
|
||||
|
||||
public void ToggleCenter()
|
||||
{
|
||||
isCenter = !isCenter;
|
||||
}
|
||||
public void SetCenter(bool isCenter)
|
||||
{
|
||||
this.isCenter = isCenter;
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
targetOffset = Vector3.zero;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (isCenter)
|
||||
{
|
||||
targetOffset= Vector3.zero;
|
||||
freelook.m_Orbits[1].m_Radius = Mathf.Lerp(freelook.m_Orbits[1].m_Radius, initRadius, Time.deltaTime * cameraSpeed);
|
||||
}
|
||||
else
|
||||
{
|
||||
targetOffset = offset.localPosition;
|
||||
freelook.m_Orbits[1].m_Radius = Mathf.Lerp(freelook.m_Orbits[1].m_Radius, aimingRadius, Time.deltaTime*cameraSpeed);
|
||||
}
|
||||
childCam.transform.localPosition= Vector3.Lerp(childCam.transform.localPosition, targetOffset, Time.deltaTime*cameraSpeed);
|
||||
}
|
||||
}
|
11
Assets/Scripts/Player/CameraShift.cs.meta
Normal file
11
Assets/Scripts/Player/CameraShift.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4d2cf1ca1f9d2e64e98d70fb574f0316
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -20,7 +20,12 @@ public class PlayerAnimationController : MonoBehaviour
|
||||
private bool movementInterrupt = false;
|
||||
[SerializeField]
|
||||
private PlayerInteractionHandler interactionHandler;
|
||||
|
||||
[SerializeField]
|
||||
private PlayerMovementController movement;
|
||||
|
||||
private float verticalAiming = 0;
|
||||
[SerializeField]
|
||||
private Camera hiddenCam;
|
||||
|
||||
public void Animate(Vector2 movement,bool jump,bool isMoving)
|
||||
{
|
||||
@ -59,6 +64,35 @@ public class PlayerAnimationController : MonoBehaviour
|
||||
{
|
||||
animController.SetBool("IsCarrying", interactionHandler.IsCarrying);
|
||||
animController.SetBool("HasGun",interactionHandler.GunEnabled);
|
||||
|
||||
if (interactionHandler.GunEnabled&&!interactionHandler.isDead&&movement.AllowRotation)
|
||||
{
|
||||
|
||||
|
||||
if (hiddenCam.transform.localEulerAngles.x < 90)
|
||||
{
|
||||
//DOWN
|
||||
float target = Mathf.Lerp(animController.GetLayerWeight(3), hiddenCam.transform.localEulerAngles.x / 70f,Time.deltaTime*10f);
|
||||
animController.SetLayerWeight(3, target);
|
||||
animController.SetLayerWeight(2, 0);
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//UP
|
||||
animController.SetLayerWeight(3, 0);
|
||||
float target = Mathf.Lerp(animController.GetLayerWeight(2), (360f - hiddenCam.transform.localEulerAngles.x) / (360f - 300f),Time.deltaTime*10);
|
||||
animController.SetLayerWeight(2, target);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
animController.SetLayerWeight(2, Mathf.Lerp(animController.GetLayerWeight(2),0,Time.deltaTime*10));
|
||||
animController.SetLayerWeight(3, Mathf.Lerp(animController.GetLayerWeight(3), 0, Time.deltaTime*10));
|
||||
}
|
||||
|
||||
//print("carrying:" + interactionHandler.IsCarrying + " running:"+animController.GetBool(runningParameter)+" running speed:" + animController.GetFloat(runningSpeedParameter));
|
||||
}
|
||||
|
@ -86,6 +86,11 @@ public class PlayerComponent : MonoBehaviour
|
||||
shakeTimer = time;
|
||||
}
|
||||
|
||||
public void SetSensitivity(float magnitude)
|
||||
{
|
||||
movementController.SetSensitivity(magnitude);
|
||||
}
|
||||
|
||||
public void Damage(float damage,bool applyShake=false)
|
||||
{
|
||||
this.health-=damage;
|
||||
|
@ -43,7 +43,8 @@ public class PlayerInteractionHandler : MonoBehaviour
|
||||
private NoiseVisibilitySettingsManager noiseManager;
|
||||
|
||||
private InGameManager manager;
|
||||
|
||||
[SerializeField]
|
||||
private CameraShift shift;
|
||||
|
||||
public bool isDead = false;
|
||||
//Check if button down
|
||||
@ -249,12 +250,14 @@ public class PlayerInteractionHandler : MonoBehaviour
|
||||
|
||||
float aimAxis = Input.GetAxis("Aim");
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
shift.SetCenter(!this.GunEnabled);
|
||||
}
|
||||
public void EnableFlashlight()
|
||||
{
|
||||
|
@ -49,6 +49,8 @@ public class PlayerMovementController : MonoBehaviour
|
||||
private bool movementLocked = false;
|
||||
[SerializeField]
|
||||
private CinemachineFreeLook freelook;
|
||||
private float initXSensitivity = 250f;
|
||||
private float initYSensitivity = 10f;
|
||||
[SerializeField]
|
||||
private string mouseXAxis = "Mouse X";
|
||||
[SerializeField]
|
||||
@ -66,6 +68,11 @@ public class PlayerMovementController : MonoBehaviour
|
||||
}
|
||||
isRunning = (Mathf.Abs(y) > 0.1f || Mathf.Abs(x) > 0.1f);
|
||||
}
|
||||
public void SetSensitivity(float sensitivity)
|
||||
{
|
||||
this.freelook.m_XAxis.m_MaxSpeed = initXSensitivity * sensitivity;
|
||||
this.freelook.m_YAxis.m_MaxValue= initYSensitivity * sensitivity;
|
||||
}
|
||||
private void MovePlayer()
|
||||
{
|
||||
Vector3 movement = Vector3.zero;
|
||||
@ -95,6 +102,8 @@ public class PlayerMovementController : MonoBehaviour
|
||||
{
|
||||
ccForceAddon = ccontroller.gameObject.GetComponent<CharacterControllerForce>();
|
||||
manager = GameObject.FindObjectOfType<InGameManager>();
|
||||
initXSensitivity =freelook.m_XAxis.m_MaxSpeed;
|
||||
initYSensitivity= freelook.m_YAxis.m_MaxSpeed;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
@ -117,6 +126,7 @@ public class PlayerMovementController : MonoBehaviour
|
||||
|
||||
SlowLookAt(this.lookingDirectionVector);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user