added GUI and pausing and finished death
This commit is contained in:
@ -43,6 +43,8 @@ public class SkinlessMonsterComponent : MonoBehaviour
|
||||
private float newTargetCooldown = 5f;
|
||||
private float timeSinceTarget = 0f;
|
||||
|
||||
private InGameManager manager;
|
||||
private bool prePauseStoppedState = false;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@ -56,6 +58,7 @@ public class SkinlessMonsterComponent : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
manager = GameObject.FindObjectOfType<InGameManager>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
@ -65,6 +68,10 @@ public class SkinlessMonsterComponent : MonoBehaviour
|
||||
targetObject = new GameObject();
|
||||
targetObject.name = "Enemy Target";
|
||||
|
||||
if(player == null)
|
||||
{
|
||||
player = GameObject.FindObjectOfType<PlayerComponent>();
|
||||
}
|
||||
}
|
||||
|
||||
void HandleTargetOperations()
|
||||
@ -272,7 +279,7 @@ public class SkinlessMonsterComponent : MonoBehaviour
|
||||
closestDistance = bDist;
|
||||
}
|
||||
}
|
||||
if (closestBullet != null)
|
||||
if (closestBullet != null&&closestBullet.DamageRange==0)
|
||||
{
|
||||
|
||||
targetObject.transform.position= closestBullet.transform.position;
|
||||
@ -304,6 +311,8 @@ public class SkinlessMonsterComponent : MonoBehaviour
|
||||
SetLiveTargeting();
|
||||
timeSinceTarget += Time.deltaTime;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
AI Behavior:
|
||||
A. If not targeting player
|
||||
|
8
Assets/Scripts/Game.meta
Normal file
8
Assets/Scripts/Game.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 32bb8ee4a70c926438bc8c849ca246c3
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
154
Assets/Scripts/Game/InGameManager.cs
Normal file
154
Assets/Scripts/Game/InGameManager.cs
Normal file
@ -0,0 +1,154 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
|
||||
|
||||
public class InGameManager : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField]
|
||||
private Volume gameVolume;
|
||||
[SerializeField]
|
||||
private Volume pausedVolume;
|
||||
|
||||
[SerializeField]
|
||||
private bool isPaused = false;
|
||||
private bool isTransitioning = false;
|
||||
|
||||
[SerializeField]
|
||||
private float pauseTransitionDuration = 1f;
|
||||
|
||||
[SerializeField]
|
||||
private Canvas gameCanvas;
|
||||
[SerializeField]
|
||||
private Canvas pausedCanvas;
|
||||
|
||||
public bool IsPaused { get { return this.isPaused; } }
|
||||
|
||||
public void TogglePause()
|
||||
{
|
||||
if (!isTransitioning)
|
||||
{
|
||||
isPaused = !isPaused;
|
||||
Cursor.visible = isPaused;
|
||||
if (!isPaused)
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
}
|
||||
else
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
}
|
||||
StartCoroutine(pauseTransition());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
public void UnPause()
|
||||
{
|
||||
if (!isTransitioning)
|
||||
{
|
||||
isPaused = false;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
Cursor.visible = isPaused;
|
||||
StartCoroutine(pauseTransition());
|
||||
}
|
||||
|
||||
}
|
||||
public void Pause()
|
||||
{
|
||||
if (!isTransitioning)
|
||||
{
|
||||
isPaused = true;
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
Cursor.visible = isPaused;
|
||||
StartCoroutine(pauseTransition());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
IEnumerator pauseTransition()
|
||||
{
|
||||
if (pausedCanvas.gameObject.activeInHierarchy && !isPaused)
|
||||
{
|
||||
pausedCanvas.gameObject.SetActive(false);
|
||||
}
|
||||
if (gameCanvas.gameObject.activeInHierarchy && isPaused)
|
||||
{
|
||||
gameCanvas.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
this.isTransitioning = true;
|
||||
yield return new WaitForSeconds(0);
|
||||
this.isTransitioning = false;
|
||||
print("Unpause canvas?" + isPaused+","+pausedCanvas.gameObject.activeInHierarchy);
|
||||
if (!pausedCanvas.gameObject.activeInHierarchy && isPaused)
|
||||
{
|
||||
pausedCanvas.gameObject.SetActive(true);
|
||||
|
||||
}
|
||||
if (!gameCanvas.gameObject.activeInHierarchy && !isPaused)
|
||||
{
|
||||
gameCanvas.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
isPaused = false;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
Cursor.visible = isPaused;
|
||||
gameVolume.weight = 1;
|
||||
pausedVolume.weight = 0;
|
||||
gameCanvas.gameObject.SetActive(true);
|
||||
pausedCanvas.gameObject.SetActive(false);
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetButtonDown("Pause"))
|
||||
{
|
||||
this.TogglePause();
|
||||
print("Toggled!");
|
||||
}
|
||||
|
||||
if (isTransitioning||true)
|
||||
{
|
||||
if (isPaused)
|
||||
{
|
||||
//transition into pause
|
||||
|
||||
//gameVolume.weight = Mathf.Lerp(gameVolume.weight, 0, Time.deltaTime);
|
||||
//pausedVolume.weight = Mathf.Lerp(pausedVolume.weight, 1, Time.deltaTime);
|
||||
|
||||
//gameVolume.weight = gameVolume.weight < 0.1 ? 0 : gameVolume.weight;
|
||||
//pausedVolume.weight = pausedVolume.weight > 0.9 ? 1 : pausedVolume.weight;
|
||||
gameVolume.weight = 0;
|
||||
pausedVolume.weight = 1;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//transition out of pause
|
||||
|
||||
gameVolume.weight = 1;
|
||||
pausedVolume.weight = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ExitToMenu()
|
||||
{
|
||||
SceneManager.LoadScene(0);
|
||||
}
|
||||
}
|
11
Assets/Scripts/Game/InGameManager.cs.meta
Normal file
11
Assets/Scripts/Game/InGameManager.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d805c17d8132601478d1da4480f05fb0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -16,6 +16,7 @@ public class BulletComponent : MonoBehaviour
|
||||
private float damageMagnitude = 1f;
|
||||
public float DamageMagnitude { get { return this.damageMagnitude; } }
|
||||
public float DamageRange { get { return damageRange; } }
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
@ -1,13 +1,14 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using static UnityEngine.UI.Image;
|
||||
|
||||
|
||||
public class PistolComponent : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Light targetingLight;
|
||||
|
||||
|
||||
private bool IsEnabled = false;
|
||||
|
||||
GameObject targetObject;
|
||||
@ -33,14 +34,13 @@ public class PistolComponent : MonoBehaviour
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
private float CalculateDrop(Vector3 origin,Vector3 destination,Vector3 force)
|
||||
{
|
||||
@ -78,6 +78,7 @@ public class PistolComponent : MonoBehaviour
|
||||
}
|
||||
public void Fire()
|
||||
{
|
||||
|
||||
GameObject projectile = Instantiate(projectilePrefab, this.bulletSpawnPoint);
|
||||
projectile.transform.localPosition = Vector3.zero;
|
||||
projectile.transform.localEulerAngles = Vector3.zero;
|
||||
@ -86,7 +87,7 @@ public class PistolComponent : MonoBehaviour
|
||||
pRigid.AddForce(pRigid.transform.up*this.firePower, ForceMode.Impulse);
|
||||
projectile.transform.parent = null;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
public void Enable()
|
||||
|
@ -25,7 +25,7 @@ public class MainMenuManager : MonoBehaviour
|
||||
{
|
||||
//initDilate = title.fontSharedMaterials[0].GetFloat(component);
|
||||
initDilate = title.fontMaterials[0].GetFloat(component);
|
||||
print(initDilate);
|
||||
|
||||
|
||||
foreach(TMP_Text text in this.textList)
|
||||
{
|
||||
@ -36,8 +36,7 @@ public class MainMenuManager : MonoBehaviour
|
||||
}
|
||||
this.textList[0].GetComponent<Button>().onClick.AddListener(LoadFirstLevel);
|
||||
this.textList[2].GetComponent<Button>().onClick.AddListener(ExitApp);
|
||||
print(this.initDilates.Count);
|
||||
print(this.dilates.Count);
|
||||
|
||||
}
|
||||
void LoadFirstLevel()
|
||||
{
|
||||
|
@ -4,6 +4,7 @@ using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
public class CameraController : MonoBehaviour
|
||||
{
|
||||
|
||||
@ -26,7 +27,7 @@ public class CameraController : MonoBehaviour
|
||||
[SerializeField]
|
||||
private bool isChild = false;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
@ -52,8 +53,8 @@ public class CameraController : MonoBehaviour
|
||||
//transform.Rotate(0, mouseX * Time.deltaTime * 180f, 0);
|
||||
//cam.transform.parent.parent.transform.Rotate(mouseY * Time.deltaTime * 180f, 0, 0);
|
||||
|
||||
Cursor.visible = false;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
//Cursor.visible = false;
|
||||
//Cursor.lockState = CursorLockMode.Locked;
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,6 +2,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Cinemachine;
|
||||
using TMPro;
|
||||
|
||||
|
||||
public class PlayerComponent : MonoBehaviour
|
||||
@ -33,6 +34,9 @@ public class PlayerComponent : MonoBehaviour
|
||||
private float knockbackDuration = 1f;
|
||||
[SerializeField]
|
||||
private float knockbackDistance = 5f;
|
||||
[SerializeField]
|
||||
private StatsOutputScreen statsOutput;
|
||||
|
||||
[HideInInspector]
|
||||
public bool IsAlive { get { return this.health > 0; } }
|
||||
private void Awake()
|
||||
@ -49,6 +53,9 @@ public class PlayerComponent : MonoBehaviour
|
||||
void Update()
|
||||
{
|
||||
NoiseManager.SetRunning(MovementController.IsRunning);
|
||||
statsOutput.health = this.health;
|
||||
statsOutput.stamina = 20f;
|
||||
statsOutput.oxygen = 100f;
|
||||
|
||||
if (shakeTimer > 0)
|
||||
{
|
||||
@ -62,6 +69,11 @@ public class PlayerComponent : MonoBehaviour
|
||||
perlin.m_AmplitudeGain = 0;
|
||||
}
|
||||
}
|
||||
if (!IsAlive)
|
||||
{
|
||||
PlayerInteractionHandler.instance.isDead = true;
|
||||
movementController.isDead = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -40,9 +40,11 @@ public class PlayerInteractionHandler : MonoBehaviour
|
||||
private PistolComponent pistol;
|
||||
[SerializeField]
|
||||
private NoiseVisibilitySettingsManager noiseManager;
|
||||
|
||||
|
||||
|
||||
private InGameManager manager;
|
||||
|
||||
|
||||
public bool isDead = false;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
@ -56,6 +58,7 @@ public class PlayerInteractionHandler : MonoBehaviour
|
||||
itemSelector = ItemSelector.instance;
|
||||
pistol.gameObject.SetActive(this.gunEnabled);
|
||||
flashlightEnabled = this.flashlight.gameObject.activeSelf;
|
||||
manager = GameObject.FindObjectOfType<InGameManager>();
|
||||
}
|
||||
|
||||
private bool receiverInRange(out int index)
|
||||
@ -77,7 +80,10 @@ public class PlayerInteractionHandler : MonoBehaviour
|
||||
void Update()
|
||||
{
|
||||
|
||||
|
||||
if (manager.IsPaused||isDead)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(Input.GetButtonDown("Fire1"))
|
||||
{
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Cinemachine;
|
||||
|
||||
public class PlayerMovementController : MonoBehaviour
|
||||
{
|
||||
@ -37,7 +38,7 @@ public class PlayerMovementController : MonoBehaviour
|
||||
[SerializeField]
|
||||
private NoiseVisibilitySettingsManager noiseSettings;
|
||||
|
||||
|
||||
private InGameManager manager;
|
||||
|
||||
|
||||
public float NoiseDistance { get { return this.noiseSettings.NoiseDistance; } }
|
||||
@ -46,11 +47,19 @@ public class PlayerMovementController : MonoBehaviour
|
||||
private Vector3 lookingDirectionVector;
|
||||
|
||||
private bool movementLocked = false;
|
||||
[SerializeField]
|
||||
private CinemachineFreeLook freelook;
|
||||
[SerializeField]
|
||||
private string mouseXAxis = "Mouse X";
|
||||
[SerializeField]
|
||||
private string mouseYAxis = "Mouse Y";
|
||||
|
||||
public bool isDead = false;
|
||||
private void GetMovementOld()
|
||||
{
|
||||
x = Input.GetAxis("Horizontal");
|
||||
y = Input.GetAxis("Vertical");
|
||||
if (movementLocked)
|
||||
if (movementLocked||manager.IsPaused)
|
||||
{
|
||||
x = 0;
|
||||
y = 0;
|
||||
@ -82,12 +91,13 @@ public class PlayerMovementController : MonoBehaviour
|
||||
void Start()
|
||||
{
|
||||
ccForceAddon = ccontroller.gameObject.GetComponent<CharacterControllerForce>();
|
||||
manager = GameObject.FindObjectOfType<InGameManager>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
if(isDead) return;
|
||||
AllowRotation = Input.GetMouseButton(1) || Input.GetAxis("Aim")>0.5f;
|
||||
GetMovementOld();
|
||||
MovePlayer();
|
||||
@ -105,7 +115,11 @@ public class PlayerMovementController : MonoBehaviour
|
||||
SlowLookAt(this.lookingDirectionVector);
|
||||
}
|
||||
|
||||
|
||||
|
||||
freelook.m_XAxis.m_InputAxisName = !manager.IsPaused ? this.mouseXAxis : "";
|
||||
freelook.m_YAxis.m_InputAxisName = !manager.IsPaused ? this.mouseYAxis : "";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
60
Assets/Scripts/Player/StatsOutputScreen.cs
Normal file
60
Assets/Scripts/Player/StatsOutputScreen.cs
Normal file
@ -0,0 +1,60 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
|
||||
public class StatsOutputScreen : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private TMP_Text healthText;
|
||||
[SerializeField]
|
||||
private TMP_Text staminaText;
|
||||
[SerializeField]
|
||||
private TMP_Text oxygenText;
|
||||
[HideInInspector]
|
||||
public float health = 0;
|
||||
[HideInInspector]
|
||||
public float stamina = 0;
|
||||
[HideInInspector]
|
||||
public float oxygen = 0;
|
||||
|
||||
private Color initColor;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
initColor = healthText.color;
|
||||
InvokeRepeating("ToggleColor", 0.5f, 0.5f);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
healthText.text = "Health:" + health.ToString();
|
||||
|
||||
if (health <= 1)
|
||||
{
|
||||
//Dark Red
|
||||
healthText.color = new Color(50,0,0);
|
||||
}
|
||||
else if (health <=3)
|
||||
{
|
||||
healthText.color = Color.red;
|
||||
}
|
||||
else
|
||||
{
|
||||
healthText.color = initColor;
|
||||
}
|
||||
|
||||
staminaText.text = "Stamina:" + stamina.ToString();
|
||||
oxygenText.text = "Oxygen:"+oxygen.ToString();
|
||||
}
|
||||
|
||||
private void ToggleColor()
|
||||
{
|
||||
if(health<=1)
|
||||
healthText.gameObject.SetActive(!healthText.gameObject.activeSelf);
|
||||
|
||||
}
|
||||
|
||||
}
|
11
Assets/Scripts/Player/StatsOutputScreen.cs.meta
Normal file
11
Assets/Scripts/Player/StatsOutputScreen.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de7389d71ec7803409f26fc6407bc153
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user