Blocks
This commit is contained in:
@@ -12,6 +12,7 @@ public class BlockManager : MonoBehaviour
|
||||
private Animation animation;
|
||||
private PlayerManager player;
|
||||
private bool action = false;
|
||||
public List<GameObject> amountModels = new List<GameObject>();
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
@@ -50,6 +51,44 @@ public class BlockManager : MonoBehaviour
|
||||
healthTime = healthRate + Time.time;
|
||||
}
|
||||
}
|
||||
viewHealthAs();
|
||||
}
|
||||
|
||||
void viewHealthAs()
|
||||
{
|
||||
if (blockType == BlockType.Wood) {
|
||||
if (amountModels.Count > 0)
|
||||
{
|
||||
for (int i = 0; i < amountModels.Count; i++)
|
||||
{
|
||||
if (i < ((100 - health) / 3.7f))
|
||||
{
|
||||
amountModels[i].SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
amountModels[i].SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (blockType == BlockType.Ammo)
|
||||
{
|
||||
if (amountModels.Count > 0)
|
||||
{
|
||||
for (int i = 0; i < amountModels.Count; i++)
|
||||
{
|
||||
if (i < ((100 - health) / 4.5f))
|
||||
{
|
||||
amountModels[i].SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
amountModels[i].SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Action()
|
||||
|
@@ -153,7 +153,7 @@ public class EnemyManager : MonoBehaviour
|
||||
void Attack()
|
||||
{
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(transform.position + new Vector3(0,0.5f,0),transform.forward,out hit,3) && attackTime <= Time.time)
|
||||
if (Physics.Raycast(transform.position + new Vector3(0,0.5f,0),transform.forward,out hit,2) && attackTime <= Time.time)
|
||||
{
|
||||
if (hit.transform.CompareTag("Player"))
|
||||
{
|
||||
|
@@ -6,6 +6,8 @@ using UnityEngine.UI;
|
||||
public class GuiManager : MonoBehaviour
|
||||
{
|
||||
public GameObject InteractIcon;
|
||||
public Text Wood;
|
||||
public Text Ammo;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
|
@@ -39,6 +39,8 @@ public class PlayerManager : MonoBehaviour
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
guiManager.Wood.text = barricadeMaterials.ToString();
|
||||
guiManager.Ammo.text = ammo.ToString();
|
||||
Move();
|
||||
RunSwitch();
|
||||
SelectWeapon();
|
||||
@@ -122,6 +124,7 @@ public class PlayerManager : MonoBehaviour
|
||||
if (Input.mouseScrollDelta.y > 0)
|
||||
{
|
||||
WeaponManager weaponManager = weaponList[selectedWeapon].GetComponent<WeaponManager>();
|
||||
weaponManager.player = this;
|
||||
if (weaponManager != null && createWeapon != null)
|
||||
{
|
||||
Destroy(createWeapon);
|
||||
@@ -137,6 +140,7 @@ public class PlayerManager : MonoBehaviour
|
||||
else if (Input.mouseScrollDelta.y < 0)
|
||||
{
|
||||
WeaponManager weaponManager = weaponList[selectedWeapon].GetComponent<WeaponManager>();
|
||||
weaponManager.player = this;
|
||||
if (weaponManager != null && createWeapon != null)
|
||||
{
|
||||
Destroy(createWeapon);
|
||||
@@ -151,6 +155,7 @@ public class PlayerManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
WeaponManager weaponManager2 = weaponList[selectedWeapon].GetComponent<WeaponManager>();
|
||||
weaponManager2.player = this;
|
||||
if (weaponManager2 != null && createWeapon == null)
|
||||
{
|
||||
createWeapon = Instantiate(weaponList[selectedWeapon]) as GameObject;
|
||||
@@ -195,9 +200,12 @@ public class PlayerManager : MonoBehaviour
|
||||
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;
|
||||
if (barricadeManager.health < (barricadeManager.barricadePlanks.Count * 50))
|
||||
{
|
||||
barricadeManager.addPlank();
|
||||
barricadeMaterials--;
|
||||
buildTime = buildRate + Time.time;
|
||||
}
|
||||
}
|
||||
if (Input.GetAxisRaw("Build") > 0 && hit.transform.tag == "Interact")
|
||||
{
|
||||
|
@@ -13,6 +13,7 @@ public class WeaponManager : MonoBehaviour
|
||||
public float fireRate = 0.5f;
|
||||
private float fireTime;
|
||||
public Animator animator;
|
||||
public PlayerManager player;
|
||||
public bool hit = false;
|
||||
|
||||
// Start is called before the first frame update
|
||||
@@ -32,18 +33,20 @@ public class WeaponManager : MonoBehaviour
|
||||
if (Input.GetMouseButtonDown(0) && fireTime <= Time.time) {
|
||||
if (weaponType == WeaponType.Shoot)
|
||||
{
|
||||
if (particleShoot != null)
|
||||
if (particleShoot != null && player.ammo > 1)
|
||||
{
|
||||
GameObject shoot = Instantiate(particleShoot, spawnShoot.transform.position, spawnShoot.transform.rotation);
|
||||
player.ammo -= 2;
|
||||
Destroy(shoot, 0.3f);
|
||||
fireTime = fireRate + Time.time;
|
||||
}
|
||||
}
|
||||
else if (weaponType == WeaponType.Meele)
|
||||
{
|
||||
animator.ResetTrigger("Hit");
|
||||
animator.SetTrigger("Hit");
|
||||
fireTime = fireRate + Time.time;
|
||||
}
|
||||
fireTime = fireRate + Time.time;
|
||||
}
|
||||
}
|
||||
void Hit_Enemy_Start()
|
||||
|
Reference in New Issue
Block a user