2020-01-31 21:32:05 +00:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
2020-02-01 13:26:43 +00:00
|
|
|
|
using UnityEngine.AI;
|
2020-01-31 21:32:05 +00:00
|
|
|
|
|
|
|
|
|
public class BarricadeManager : MonoBehaviour
|
|
|
|
|
{
|
2020-02-01 11:11:56 +00:00
|
|
|
|
public float health = 0;
|
2020-01-31 23:53:03 +00:00
|
|
|
|
public List<GameObject> barricadePlanks = new List<GameObject>();
|
2020-02-01 13:26:43 +00:00
|
|
|
|
public OffMeshLink offMeshLink;
|
2020-02-01 15:20:10 +00:00
|
|
|
|
public Transform walkPoint;
|
2020-01-31 23:53:03 +00:00
|
|
|
|
|
2020-02-01 19:58:47 +00:00
|
|
|
|
public AudioSource audioSource = new AudioSource();
|
|
|
|
|
public AudioClip buildSound;
|
|
|
|
|
|
2020-01-31 21:32:05 +00:00
|
|
|
|
// Start is called before the first frame update
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
2020-01-31 23:53:03 +00:00
|
|
|
|
viewHealthAsPlanks();
|
2020-02-01 11:11:56 +00:00
|
|
|
|
if (health < 0)
|
|
|
|
|
{
|
|
|
|
|
health = 0;
|
|
|
|
|
}
|
2020-02-01 13:26:43 +00:00
|
|
|
|
|
|
|
|
|
if (health <= 0)
|
|
|
|
|
{
|
|
|
|
|
offMeshLink.enabled = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
offMeshLink.enabled = false;
|
|
|
|
|
}
|
2020-01-31 23:53:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void addPlank()
|
|
|
|
|
{
|
2020-02-01 17:53:28 +00:00
|
|
|
|
if (health < (barricadePlanks.Count * 50)) {
|
2020-02-01 19:58:47 +00:00
|
|
|
|
audioSource.PlayOneShot(buildSound);
|
2020-02-01 17:53:28 +00:00
|
|
|
|
health += 50;
|
2020-02-01 13:26:43 +00:00
|
|
|
|
offMeshLink.enabled = false;
|
2020-01-31 23:53:03 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-01 11:11:56 +00:00
|
|
|
|
public void Damage(float damage)
|
|
|
|
|
{
|
|
|
|
|
if (health > 0) {
|
|
|
|
|
health -= damage;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-31 23:53:03 +00:00
|
|
|
|
void viewHealthAsPlanks()
|
|
|
|
|
{
|
|
|
|
|
if (barricadePlanks.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < barricadePlanks.Count; i++)
|
|
|
|
|
{
|
2020-02-01 17:53:28 +00:00
|
|
|
|
if (i < (health / 50)) {
|
2020-01-31 23:53:03 +00:00
|
|
|
|
barricadePlanks[i].SetActive(true);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
barricadePlanks[i].SetActive(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-01-31 21:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|