This commit is contained in:
JonatanRek
2020-02-01 23:28:39 +01:00
46 changed files with 10609 additions and 401 deletions

View File

@@ -132,4 +132,21 @@ public class BlockManager : MonoBehaviour
}
}
}
void OnTriggerEnter(Collider collider)
{
if (blockType == BlockType.Barricade) {
Debug.Log(collider.transform.tag);
if (collider.transform.CompareTag("Enemy"))
{
EnemyManager enemyManager = collider.transform.GetComponent<EnemyManager>();
if (enemyManager != null)
{
enemyManager.Damage(100);
health = 0;
Destroy(this.gameObject, 3);
}
}
}
}
}

View File

@@ -24,17 +24,13 @@ public class DayManager : MonoBehaviour
{
float sunRotationX = transform.localEulerAngles.x;
sunRotationX = (sunRotationX > 180) ? sunRotationX - 360 : sunRotationX;
Debug.Log(sunRotationX.ToString());
if (sunRotationX < 0 && !night)
{
Debug.Log("It is a Night");
mainSource.PlayOneShot(nigtClip);
night = true;
}
else if (sunRotationX > 0 && night)
{
Debug.Log("It is a Day");
mainSource.PlayOneShot(dayClip);
night = false;
daySurvived++;

View File

@@ -47,7 +47,7 @@ public class EnemyManager : MonoBehaviour
void FixedUpdate()
{
if (navMeshAgent.pathStatus == NavMeshPathStatus.PathComplete)
if (navMeshAgent != null && navMeshAgent.pathStatus == NavMeshPathStatus.PathComplete)
{
if (actualHealth > 0 && barricadeManager == null)
{
@@ -64,11 +64,17 @@ public class EnemyManager : MonoBehaviour
}
}
public void Damage()
public void Damage(float damageLoc = 0)
{
WeaponManager weaponManager = player.weaponList[player.selectedWeapon].GetComponent<WeaponManager>();
if (weaponManager != null) {
actualHealth -= weaponManager.damage;
if (damageLoc == 0) {
WeaponManager weaponManager = player.weaponList[player.selectedWeapon].GetComponent<WeaponManager>();
if (weaponManager != null) {
actualHealth -= weaponManager.damage;
}
}
else
{
actualHealth -= damageLoc;
}
}
@@ -153,7 +159,7 @@ public class EnemyManager : MonoBehaviour
void Attack()
{
RaycastHit hit;
if (Physics.Raycast(transform.position + new Vector3(0,0.5f,0),transform.forward,out hit,2) && attackTime <= Time.time)
if (Physics.Raycast(transform.position + new Vector3(0,0.5f,0),transform.forward,out hit,1.5f) && attackTime <= Time.time)
{
if (hit.transform.CompareTag("Player"))
{
@@ -182,10 +188,14 @@ public class EnemyManager : MonoBehaviour
void OnTriggerEnter(Collider collider)
{
Debug.Log(collider.transform.tag);
if (collider.transform.CompareTag("Meele"))
{
Damage();
WeaponManager weaponManager = collider.transform.GetComponent<WeaponManager>();
if (weaponManager != null && weaponManager.hit) {
Damage();
weaponManager.hit = false;
}
}
}
}

View File

@@ -21,8 +21,12 @@ public class GuiManager : MonoBehaviour
}
public void InteractVerifier(bool set)
public void InteractVerifier(bool set, Sprite image = null)
{
InteractIcon.SetActive(set);
if (image != null)
{
InteractIcon.GetComponent<Image>().sprite = image;
}
}
}

View File

@@ -0,0 +1,43 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NightDayParticles : MonoBehaviour
{
public GameObject parentParticle;
public bool activeInDay = false;
public bool activeInNight = false;
public DayManager dayManager;
bool night = false;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
float sunRotationX = dayManager.transform.localEulerAngles.x;
sunRotationX = (sunRotationX > 180) ? sunRotationX - 360 : sunRotationX;
if (sunRotationX < 0 && !night)
{
night = true;
}
else if (sunRotationX > 0 && night)
{
night = false;
}
if ((activeInDay && !night) || (activeInNight && night))
{
parentParticle.SetActive(true);
}
else
{
parentParticle.SetActive(false);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b0314a14d6c40f643bdaaf2fb3e0228d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -21,13 +21,19 @@ public class PlayerManager : MonoBehaviour
public int ammo = 50;
public List<GameObject> weaponList = new List<GameObject>();
private GameObject createWeapon;
public GameObject spikes;
public Sprite spikesImage;
public Sprite handImage;
public GuiManager guiManager;
[HideInInspector]public int selectedWeapon = 0;
public int selectedWeapon = 0;
private float selectRate = 1;
private float selectTime = 1;
// Start is called before the first frame update
void Start()
{
selectTime = selectRate;
actualHealth = health;
buildTime = buildRate;
playerCamera = GetComponentInChildren<Camera>();
@@ -44,7 +50,6 @@ public class PlayerManager : MonoBehaviour
Move();
RunSwitch();
SelectWeapon();
BuildBlock();
Interact();
if (actualHealth <= 0)
@@ -121,64 +126,56 @@ public class PlayerManager : MonoBehaviour
{
if (weaponList.Count > 0)
{
if (Input.mouseScrollDelta.y > 0)
{
WeaponManager weaponManager = weaponList[selectedWeapon].GetComponent<WeaponManager>();
WeaponManager weaponManager = weaponList[selectedWeapon].GetComponent<WeaponManager>();
if (weaponManager != null) {
weaponManager.player = this;
if (weaponManager != null && createWeapon != null)
Debug.Log(weaponList.Count);
if (Input.GetAxis("Mouse ScrollWheel") > 0 && selectTime < Time.time)
{
Destroy(createWeapon);
if (weaponManager != null && createWeapon != null)
{
Destroy(createWeapon);
}
}
if (weaponList.Count > selectedWeapon + 1) {
selectedWeapon++;
else if (Input.GetAxis("Mouse ScrollWheel") < 0 && selectTime < Time.time)
{
if (weaponManager != null && createWeapon != null)
{
Destroy(createWeapon);
}
}
weaponManager.player = this;
if (weaponManager != null && createWeapon == null)
{
createWeapon = Instantiate(weaponList[selectedWeapon]) as GameObject;
createWeapon.transform.parent = playerCamera.transform;
createWeapon.transform.localPosition = Vector3.zero;
createWeapon.transform.localEulerAngles = Vector3.zero;
}
}
if (Input.GetAxis("Mouse ScrollWheel") > 0 && selectTime < Time.time)
{
if (weaponList.Count - 1 > selectedWeapon)
{
selectedWeapon += 1;
}
else
{
selectedWeapon = 0;
}
selectTime = selectRate + Time.time;
}
else if (Input.mouseScrollDelta.y < 0)
else if (Input.GetAxis("Mouse ScrollWheel") < 0 && selectTime < Time.time)
{
WeaponManager weaponManager = weaponList[selectedWeapon].GetComponent<WeaponManager>();
weaponManager.player = this;
if (weaponManager != null && createWeapon != null)
{
Destroy(createWeapon);
}
if (selectedWeapon > 0)
{
selectedWeapon--;
selectedWeapon -= 1;
}
else
{
selectedWeapon = weaponList.Count - 1;
}
}
WeaponManager weaponManager2 = weaponList[selectedWeapon].GetComponent<WeaponManager>();
weaponManager2.player = this;
if (weaponManager2 != null && createWeapon == null)
{
createWeapon = Instantiate(weaponList[selectedWeapon]) as GameObject;
createWeapon.transform.parent = playerCamera.transform;
createWeapon.transform.localPosition = Vector3.zero;
createWeapon.transform.localEulerAngles = Vector3.zero;
}
}
}
void BuildBlock ()
{
if (Input.GetAxisRaw("Fire1") > 0 && buildTime < Time.time && weaponList.Count > 0)
{
Ray ray = playerCamera.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, Mathf.Infinity, LayerMask.GetMask("BuildPlace")))
{
BlockManager blockManager = weaponList[selectedWeapon].GetComponent<BlockManager>();
if (blockManager != null) {
Instantiate(weaponList[selectedWeapon], hit.point, transform.rotation);
buildTime = buildRate + Time.time;
}
selectTime = selectRate + Time.time;
}
}
}
@@ -189,13 +186,24 @@ public class PlayerManager : MonoBehaviour
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 2))
{
if (hit.transform.CompareTag("BarricadeField") || hit.transform.CompareTag("Interact"))
if (hit.transform.CompareTag("BarricadeField") || hit.transform.CompareTag("Interact") || hit.transform.gameObject.layer == LayerMask.NameToLayer("BuildPlace"))
{
guiManager.InteractVerifier(true);
BlockManager blockManager = hit.transform.GetComponent<BlockManager>();
if (blockManager == null || blockManager.blockType != BlockManager.BlockType.Barricade) {
guiManager.InteractVerifier(true, handImage);
if (hit.transform.gameObject.layer == LayerMask.NameToLayer("BuildPlace"))
{
guiManager.InteractVerifier(true, spikesImage);
}
}
else
{
guiManager.InteractVerifier(false, handImage);
}
}
else
{
guiManager.InteractVerifier(false);
guiManager.InteractVerifier(false, handImage);
}
if (Input.GetAxisRaw("Build") > 0 && buildTime < Time.time && barricadeMaterials > 0 && hit.transform.tag == "BarricadeField")
{
@@ -214,7 +222,15 @@ public class PlayerManager : MonoBehaviour
{
BlockManager blockManager = hit.transform.GetComponent<BlockManager>();
blockManager.Action();
}
else if (hit.transform.gameObject.layer == LayerMask.NameToLayer("BuildPlace") && Input.GetKeyDown(KeyCode.E) && buildTime < Time.time)
{
BlockManager blockManager = spikes.GetComponent<BlockManager>();
if (blockManager != null)
{
Instantiate<GameObject>(spikes, hit.point, transform.rotation);
buildTime = buildRate + Time.time;
}
}
}
else

View File

@@ -27,13 +27,10 @@ public class SpawnManager : MonoBehaviour
float sunRotationX = Sun.transform.localEulerAngles.x;
sunRotationX = (sunRotationX > 180) ? sunRotationX - 360 : sunRotationX;
Debug.Log(sunRotationX.ToString());
if (sunRotationX < 0)
{
Debug.Log("It is a Night");
night = true;
} else {
Debug.Log("It is a Day");
night = false;
}

View File

@@ -47,19 +47,15 @@ public class WeaponManager : MonoBehaviour
}
else if (weaponType == WeaponType.Meele)
{
hit = true;
animator.ResetTrigger("Hit");
animator.SetTrigger("Hit");
fireTime = fireRate + Time.time;
}
}
}
void Hit_Enemy_Start()
{
hit = true;
}
void Hit_Enemy_End()
{
hit = false;
if (fireTime <= Time.time)
{
hit = false;
}
}
}