GlobalGameJame/Assets/Scripts/BarricadeManager.cs

73 lines
1.5 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class BarricadeManager : MonoBehaviour
{
public float health = 0;
public List<GameObject> barricadePlanks = new List<GameObject>();
public OffMeshLink offMeshLink;
public Transform walkPoint;
public AudioSource audioSource = new AudioSource();
public AudioClip buildSound;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
viewHealthAsPlanks();
if (health < 0)
{
health = 0;
}
if (health <= 0)
{
offMeshLink.enabled = true;
}
else
{
offMeshLink.enabled = false;
}
}
public void addPlank()
{
if (health < (barricadePlanks.Count * 50)) {
audioSource.PlayOneShot(buildSound);
health += 50;
offMeshLink.enabled = false;
}
}
public void Damage(float damage)
{
if (health > 0) {
health -= damage;
}
}
void viewHealthAsPlanks()
{
if (barricadePlanks.Count > 0)
{
for (int i = 0; i < barricadePlanks.Count; i++)
{
if (i < (health / 50)) {
barricadePlanks[i].SetActive(true);
}
else
{
barricadePlanks[i].SetActive(false);
}
}
}
}
}