imported music, added combat and death
This commit is contained in:
72
Assets/Scripts/Player/NoiseVisibilitySettingsManager.cs
Normal file
72
Assets/Scripts/Player/NoiseVisibilitySettingsManager.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
public class NoiseVisibilitySettingsManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private float sneakNoiseDistance = 5f;
|
||||
[SerializeField]
|
||||
private float runNoiseDistance = 10f;
|
||||
[SerializeField]
|
||||
private float shootNoiseDistance = 30f;
|
||||
[SerializeField]
|
||||
private float standNoiseDistance = 0f;
|
||||
private float noiseDistance = 0f;
|
||||
|
||||
public float SneakNoiseDistance { get { return sneakNoiseDistance; } }
|
||||
public float RunNoiseDistance { get { return runNoiseDistance; } }
|
||||
public float ShootNoiseDistance { get { return shootNoiseDistance; } }
|
||||
public float StandNoiseDistance { get { return standNoiseDistance; } }
|
||||
|
||||
public float NoiseDistance { get { return this.noiseDistance; } }
|
||||
|
||||
private float timeSinceLastShot = 0f;
|
||||
[SerializeField]
|
||||
private float shootNoiseDuration = 2f;
|
||||
private bool isSneaking = false;
|
||||
private bool isRunning = false;
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (timeSinceLastShot>0)
|
||||
{
|
||||
this.noiseDistance = this.shootNoiseDistance;
|
||||
}
|
||||
else if (isRunning)
|
||||
{
|
||||
this.noiseDistance = this.runNoiseDistance;
|
||||
}else if (isSneaking)
|
||||
{
|
||||
this.noiseDistance = this.sneakNoiseDistance;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.noiseDistance = standNoiseDistance;
|
||||
}
|
||||
|
||||
timeSinceLastShot -= Time.deltaTime;
|
||||
}
|
||||
|
||||
public void ShotFired()
|
||||
{
|
||||
this.timeSinceLastShot = this.shootNoiseDuration;
|
||||
}
|
||||
public void SetRunning(bool isRunning)
|
||||
{
|
||||
this.isRunning = isRunning;
|
||||
}
|
||||
public void SetSneaking(bool isSneaking)
|
||||
{
|
||||
this.isSneaking= isSneaking;
|
||||
}
|
||||
}
|
11
Assets/Scripts/Player/NoiseVisibilitySettingsManager.cs.meta
Normal file
11
Assets/Scripts/Player/NoiseVisibilitySettingsManager.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1179093e6fa69e045838868718a12c58
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -42,9 +42,10 @@ public class PlayerAnimationController : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void Hit()
|
||||
public void Hit(bool isDead)
|
||||
{
|
||||
animController.SetTrigger("WasHit");
|
||||
animController.SetBool("IsDead", isDead);
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
|
98
Assets/Scripts/Player/PlayerComponent.cs
Normal file
98
Assets/Scripts/Player/PlayerComponent.cs
Normal file
@ -0,0 +1,98 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Cinemachine;
|
||||
|
||||
|
||||
public class PlayerComponent : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private float health = 5f;
|
||||
[SerializeField]
|
||||
private float maxHealth = 5f;
|
||||
[SerializeField]
|
||||
private float stamina = 20f;
|
||||
[SerializeField]
|
||||
private float maxStamina = 20f;
|
||||
|
||||
[SerializeField] private NoiseVisibilitySettingsManager noiseManager;
|
||||
[SerializeField] private PlayerMovementController movementController;
|
||||
|
||||
public NoiseVisibilitySettingsManager NoiseManager { get { return this.noiseManager; } }
|
||||
public PlayerMovementController MovementController { get { return movementController; } }
|
||||
[SerializeField]
|
||||
private PlayerAnimationController animationController;
|
||||
|
||||
[HideInInspector]
|
||||
public FlareRegister flareRegister;
|
||||
[SerializeField]
|
||||
private CinemachineFreeLook cameraFreeLook;
|
||||
private float shakeTimer = 0;
|
||||
CinemachineBasicMultiChannelPerlin perlin;
|
||||
[SerializeField]
|
||||
private float knockbackDuration = 1f;
|
||||
[SerializeField]
|
||||
private float knockbackDistance = 5f;
|
||||
[HideInInspector]
|
||||
public bool IsAlive { get { return this.health > 0; } }
|
||||
private void Awake()
|
||||
{
|
||||
flareRegister = GameObject.FindObjectOfType<FlareRegister>();
|
||||
}
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
perlin = cameraFreeLook.GetRig(1).GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
NoiseManager.SetRunning(MovementController.IsRunning);
|
||||
|
||||
if (shakeTimer > 0)
|
||||
{
|
||||
shakeTimer -= Time.deltaTime;
|
||||
|
||||
// perlin.m_AmplitudeGain = 0;
|
||||
perlin.m_AmplitudeGain = Mathf.Lerp(perlin.m_AmplitudeGain, 0, .1f);
|
||||
if (shakeTimer <= 0f)
|
||||
{
|
||||
|
||||
perlin.m_AmplitudeGain = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void ShakeCamera(float intensity, float time)
|
||||
{
|
||||
CinemachineBasicMultiChannelPerlin perlin = cameraFreeLook.GetRig(1).GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
|
||||
perlin.m_AmplitudeGain= intensity;
|
||||
shakeTimer = time;
|
||||
}
|
||||
|
||||
public void Damage(float damage,bool applyShake=false)
|
||||
{
|
||||
this.health-=damage;
|
||||
if (applyShake)
|
||||
{
|
||||
ShakeCamera(15, 5);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.CompareTag("Damaging"))
|
||||
{
|
||||
MonsterComponent monster = other.GetComponentInParent<MonsterComponent>();
|
||||
|
||||
this.Damage(monster.AttackDamage, monster.ShakeCameraOnHit);
|
||||
animationController.Hit(this.health<=0);
|
||||
this.movementController.PhysicalForceMove((transform.position - monster.transform.position)*knockbackDistance);
|
||||
this.movementController.LockMovement(this.knockbackDuration);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Player/PlayerComponent.cs.meta
Normal file
11
Assets/Scripts/Player/PlayerComponent.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 86fd72b889d47804e844e0bc9c04218d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -38,6 +38,9 @@ public class PlayerInteractionHandler : MonoBehaviour
|
||||
private bool useItemSelector = true;
|
||||
[SerializeField]
|
||||
private PistolComponent pistol;
|
||||
[SerializeField]
|
||||
private NoiseVisibilitySettingsManager noiseManager;
|
||||
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
@ -83,6 +86,7 @@ public class PlayerInteractionHandler : MonoBehaviour
|
||||
if (tempInvent.GetQuantityOf(this.pistol.projectileName) > 0)
|
||||
{
|
||||
this.pistol.Fire();
|
||||
this.noiseManager.ShotFired();
|
||||
tempInvent.Remove(this.pistol.projectileName);
|
||||
}
|
||||
|
||||
|
@ -12,9 +12,12 @@ public class PlayerMovementController : MonoBehaviour
|
||||
private float mouseX = 0;
|
||||
|
||||
private bool isRunning = false;
|
||||
private bool isSneaking = false;
|
||||
public bool IsRunning { get { return isRunning; } }
|
||||
[SerializeField]
|
||||
private CharacterController ccontroller;
|
||||
|
||||
private CharacterControllerForce ccForceAddon;
|
||||
|
||||
[SerializeField]
|
||||
private CameraController cameraController;
|
||||
|
||||
@ -31,13 +34,27 @@ public class PlayerMovementController : MonoBehaviour
|
||||
[HideInInspector]
|
||||
public bool AllowRotation = false;
|
||||
|
||||
[SerializeField]
|
||||
private NoiseVisibilitySettingsManager noiseSettings;
|
||||
|
||||
|
||||
|
||||
|
||||
public float NoiseDistance { get { return this.noiseSettings.NoiseDistance; } }
|
||||
|
||||
|
||||
private Vector3 lookingDirectionVector;
|
||||
|
||||
private bool movementLocked = false;
|
||||
private void GetMovementOld()
|
||||
{
|
||||
x = Input.GetAxis("Horizontal");
|
||||
y = Input.GetAxis("Vertical");
|
||||
if (movementLocked)
|
||||
{
|
||||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
isRunning = (Mathf.Abs(y) > 0.1f || Mathf.Abs(x) > 0.1f);
|
||||
}
|
||||
private void MovePlayer()
|
||||
@ -64,13 +81,14 @@ public class PlayerMovementController : MonoBehaviour
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
ccForceAddon = ccontroller.gameObject.GetComponent<CharacterControllerForce>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
AllowRotation = Input.GetMouseButton(1);
|
||||
|
||||
AllowRotation = Input.GetMouseButton(1) || Input.GetAxis("Aim")>0.5f;
|
||||
GetMovementOld();
|
||||
MovePlayer();
|
||||
|
||||
@ -86,8 +104,13 @@ public class PlayerMovementController : MonoBehaviour
|
||||
|
||||
SlowLookAt(this.lookingDirectionVector);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void SlowLookAt(Vector3 targetVector)
|
||||
{
|
||||
Vector3 relativePos = targetVector;
|
||||
@ -96,4 +119,21 @@ public class PlayerMovementController : MonoBehaviour
|
||||
transform.rotation = Quaternion.Lerp(transform.rotation, toRotation, animatedRotationSpeed * Time.deltaTime);
|
||||
|
||||
}
|
||||
|
||||
public void PhysicalForceMove(Vector3 vector)
|
||||
{
|
||||
this.ccontroller.Move(vector);
|
||||
ccForceAddon.AddImpact(vector, vector.magnitude);
|
||||
|
||||
}
|
||||
public void LockMovement(float duration)
|
||||
{
|
||||
StartCoroutine(lockMovement(duration));
|
||||
}
|
||||
private IEnumerator lockMovement(float duration)
|
||||
{
|
||||
movementLocked = true;
|
||||
yield return new WaitForSeconds(duration);
|
||||
movementLocked = false;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user