next commit 5

This commit is contained in:
Kotrba Filip
2020-02-01 00:53:03 +01:00
parent 727fab43b2
commit e03eafaf7b
12 changed files with 7663 additions and 93 deletions

View File

@@ -4,6 +4,9 @@ using UnityEngine;
public class BarricadeManager : MonoBehaviour
{
public int health = 0;
public List<GameObject> barricadePlanks = new List<GameObject>();
// Start is called before the first frame update
void Start()
{
@@ -13,6 +16,30 @@ public class BarricadeManager : MonoBehaviour
// Update is called once per frame
void Update()
{
viewHealthAsPlanks();
}
public void addPlank()
{
if (health < (barricadePlanks.Count * 10)) {
health += 10;
}
}
void viewHealthAsPlanks()
{
if (barricadePlanks.Count > 0)
{
for (int i = 0; i < barricadePlanks.Count; i++)
{
if (i < (health / 10)) {
barricadePlanks[i].SetActive(true);
}
else
{
barricadePlanks[i].SetActive(false);
}
}
}
}
}

View File

@@ -9,15 +9,16 @@ public class PlayerManager : MonoBehaviour
public float runSpeed = 25;
public float rotateSpeed = 5;
public float mouseSensitive = 200;
public float fireRate = 2;
public float fireRate = 1;
private float fireTime;
public float buildRate = 0.5f;
private float buildTime;
private bool run = false;
private Camera playerCamera;
private Rigidbody rigidBody;
public int baricadeMaterials = 10;
public int barricadeMaterials = 10;
public List<GameObject> weaponList = new List<GameObject>();
private GameObject createWeapon;
[HideInInspector]public int selectedWeapon = 0;
@@ -39,6 +40,8 @@ public class PlayerManager : MonoBehaviour
RunSwitch();
SelectWeapon();
BuildBlock();
BuildBarricade();
Attack();
}
void FixedUpdate()
@@ -57,6 +60,7 @@ public class PlayerManager : MonoBehaviour
void Rotate()
{
Debug.Log(playerCamera.transform.localEulerAngles);
transform.Rotate(new Vector3(0, rotateSpeed * Input.GetAxis("Mouse X") * mouseSensitive * Time.deltaTime, 0));
if (
((playerCamera.transform.localEulerAngles.x >= 270 && playerCamera.transform.localEulerAngles.x <= 360) &&
@@ -80,6 +84,10 @@ public class PlayerManager : MonoBehaviour
) {
playerCamera.transform.Rotate(new Vector3(rotateSpeed * (-Input.GetAxis("Mouse Y") < 0 ? -Input.GetAxis("Mouse Y") : 0) * mouseSensitive * Time.deltaTime, 0, 0));
}
else
{
playerCamera.transform.Rotate(new Vector3(rotateSpeed * -Input.GetAxis("Mouse Y") * mouseSensitive * Time.deltaTime, 0, 0));
}
}
void RunSwitch()
@@ -100,6 +108,11 @@ public class PlayerManager : MonoBehaviour
{
if (Input.mouseScrollDelta.y > 0)
{
WeaponManager weaponManager = weaponList[selectedWeapon].GetComponent<WeaponManager>();
if (weaponManager != null && createWeapon != null)
{
Destroy(createWeapon);
}
if (weaponList.Count > selectedWeapon + 1) {
selectedWeapon++;
}
@@ -110,6 +123,11 @@ public class PlayerManager : MonoBehaviour
}
else if (Input.mouseScrollDelta.y < 0)
{
WeaponManager weaponManager = weaponList[selectedWeapon].GetComponent<WeaponManager>();
if (weaponManager != null && createWeapon != null)
{
Destroy(createWeapon);
}
if (selectedWeapon > 0)
{
selectedWeapon--;
@@ -119,6 +137,14 @@ public class PlayerManager : MonoBehaviour
selectedWeapon = weaponList.Count - 1;
}
}
WeaponManager weaponManager2 = weaponList[selectedWeapon].GetComponent<WeaponManager>();
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;
}
}
}
@@ -139,11 +165,29 @@ public class PlayerManager : MonoBehaviour
}
}
void Attack()
{
WeaponManager weaponManager = weaponList[selectedWeapon].GetComponent<WeaponManager>();
if (weaponManager != null && Input.GetMouseButtonDown(0) && fireTime < Time.time)
{
weaponManager.Attack();
fireTime = fireRate * Time.time;
}
}
void BuildBarricade()
{
if ()
Ray ray = playerCamera.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 1))
{
if (Input.GetAxisRaw("Build") > 0 && buildTime < Time.time && barricadeMaterials > 0 && hit.transform.tag == "BarricadeField")
{
BarricadeManager barricadeManager = hit.transform.GetComponent<BarricadeManager>();
barricadeManager.addPlank();
barricadeMaterials--;
buildTime = buildRate + Time.time;
}
}
}
}

View File

@@ -0,0 +1,47 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WeaponManager : MonoBehaviour
{
public enum WeaponType { None, Shoot, Meele };
public WeaponType weaponType = WeaponType.None;
public float weaponRange = 1;
public ParticleSystem particleShoot;
public float damage = 0;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void Attack()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, weaponRange))
{
}
if (weaponType == WeaponType.Shoot)
{
if (particleShoot != null && !particleShoot.isPlaying)
{
particleShoot.Stop();
particleShoot.Play();
}
}
else if (weaponType == WeaponType.Meele)
{
}
}
}

View File

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