Repair spikes add health bar and change vizualization of info about amout of wood and ammo
This commit is contained in:
@@ -38,6 +38,7 @@ public class BlockManager : MonoBehaviour
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
SpikeHit();
|
||||
if (blockType == BlockType.Wood)
|
||||
{
|
||||
if (health < 100 && healthTime < Time.time)
|
||||
@@ -133,18 +134,26 @@ public class BlockManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
void OnCollisionEnter(Collision collision)
|
||||
void SpikeHit()
|
||||
{
|
||||
if (blockType == BlockType.Barricade) {
|
||||
Debug.Log(collision.transform.tag);
|
||||
if (collision.transform.CompareTag("Enemy"))
|
||||
RaycastHit hit;
|
||||
if (Physics.BoxCast(this.transform.position + new Vector3(-0.05f, 0.75f, 1.0f), new Vector3(0.5f, 0.75f, 1.0f), this.transform.forward, out hit, transform.rotation,1.0f))
|
||||
{
|
||||
EnemyManager enemyManager = collision.transform.GetComponent<EnemyManager>();
|
||||
if (enemyManager != null)
|
||||
if (hit.collider.CompareTag("Enemy"))
|
||||
{
|
||||
enemyManager.Damage(100);
|
||||
health = 0;
|
||||
Destroy(this.gameObject, 3);
|
||||
EnemyManager enemyManager = hit.collider.transform.GetComponent<EnemyManager>();
|
||||
if (enemyManager != null)
|
||||
{
|
||||
enemyManager.Damage(100);
|
||||
health = 0;
|
||||
for (int i = 0; i < amountModels.Count; i++)
|
||||
{
|
||||
amountModels[i].transform.parent = null;
|
||||
Destroy(amountModels[i], 4);
|
||||
}
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -10,6 +10,8 @@ public class EnemyManager : MonoBehaviour
|
||||
public float attackRate = 2;
|
||||
private float attackTime = 2;
|
||||
public float actualHealth;
|
||||
public float findRate = 1;
|
||||
private float findTime = 1;
|
||||
private NavMeshAgent navMeshAgent;
|
||||
private PlayerManager player;
|
||||
public BarricadeManager barricadeManager;
|
||||
@@ -18,6 +20,7 @@ public class EnemyManager : MonoBehaviour
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
findTime = findRate;
|
||||
attackTime = attackRate;
|
||||
actualHealth = health;
|
||||
player = FindObjectOfType<PlayerManager>();
|
||||
@@ -35,32 +38,31 @@ public class EnemyManager : MonoBehaviour
|
||||
DestroyBarricades();
|
||||
Attack();
|
||||
|
||||
if (navMeshAgent != null && barricadeManager == null)
|
||||
if (navMeshAgent != null && barricadeManager == null && findTime < Time.time)
|
||||
{
|
||||
navMeshAgent.SetDestination(player.transform.position);
|
||||
findTime = findRate + Time.time;
|
||||
}
|
||||
else if (navMeshAgent != null && barricadeManager != null)
|
||||
else if (navMeshAgent != null && barricadeManager != null && findTime < Time.time)
|
||||
{
|
||||
navMeshAgent.SetDestination(new Vector3(barricadeManager.walkPoint.position.x, 0, barricadeManager.walkPoint.position.z));
|
||||
navMeshAgent.SetDestination(barricadeManager.transform.position);
|
||||
findTime = findRate + Time.time;
|
||||
}
|
||||
}
|
||||
|
||||
void FixedUpdate()
|
||||
{
|
||||
if (navMeshAgent != null && navMeshAgent.pathStatus == NavMeshPathStatus.PathComplete)
|
||||
if (actualHealth > 0 && barricadeManager == null)
|
||||
{
|
||||
if (actualHealth > 0 && barricadeManager == null)
|
||||
{
|
||||
Vector3 _dir = player.transform.position - transform.position;
|
||||
_dir.Normalize();
|
||||
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(_dir), 5 * Time.deltaTime);
|
||||
}
|
||||
else if (actualHealth > 0 && barricadeManager != null)
|
||||
{
|
||||
Vector3 _dir = barricadeManager.transform.position - transform.position;
|
||||
_dir.Normalize();
|
||||
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(_dir), 5 * Time.deltaTime);
|
||||
}
|
||||
Vector3 _dir = player.transform.position - transform.position;
|
||||
_dir.Normalize();
|
||||
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(_dir), 5 * Time.deltaTime);
|
||||
}
|
||||
else if (actualHealth > 0 && barricadeManager != null)
|
||||
{
|
||||
Vector3 _dir = barricadeManager.transform.position - transform.position;
|
||||
_dir.Normalize();
|
||||
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(_dir), 5 * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,6 +85,7 @@ public class EnemyManager : MonoBehaviour
|
||||
NavMeshPath path = new NavMeshPath();
|
||||
if (navMeshAgent != null) {
|
||||
navMeshAgent.CalculatePath(player.transform.position, path);
|
||||
Debug.Log(path.status);
|
||||
if (path.status == NavMeshPathStatus.PathPartial)
|
||||
{
|
||||
BarricadeManager[] barricadeManagers = GameObject.FindObjectsOfType<BarricadeManager>();
|
||||
@@ -94,8 +97,14 @@ public class EnemyManager : MonoBehaviour
|
||||
}
|
||||
else
|
||||
{
|
||||
if (localBarricadeManager.health < barricadeManager.health || Vector3.Distance(barricadeManager.transform.position, transform.position) > Vector3.Distance(localBarricadeManager.transform.position, transform.position)) {
|
||||
if (localBarricadeManager.health < barricadeManager.health) {
|
||||
barricadeManager = localBarricadeManager;
|
||||
continue;
|
||||
}
|
||||
if (Vector3.Distance(barricadeManager.transform.position, transform.position) > Vector3.Distance(localBarricadeManager.transform.position, transform.position))
|
||||
{
|
||||
barricadeManager = localBarricadeManager;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -197,19 +206,4 @@ public class EnemyManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
if (collision.transform.CompareTag("Spikes"))
|
||||
{
|
||||
BlockManager blockManager = GetComponent<Collider>().transform.GetComponent<BlockManager>();
|
||||
if (blockManager != null && blockManager.blockType == BlockManager.BlockType.Barricade)
|
||||
{
|
||||
Damage(100);
|
||||
blockManager.health = 0;
|
||||
Destroy(blockManager);
|
||||
Destroy(blockManager.gameObject, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -8,6 +8,7 @@ public class GuiManager : MonoBehaviour
|
||||
public GameObject InteractIcon;
|
||||
public Text Wood;
|
||||
public Text Ammo;
|
||||
public Image healthBar;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
@@ -29,4 +30,9 @@ public class GuiManager : MonoBehaviour
|
||||
InteractIcon.GetComponent<Image>().sprite = image;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetHealth(float health)
|
||||
{
|
||||
healthBar.fillAmount = health;
|
||||
}
|
||||
}
|
||||
|
@@ -56,6 +56,9 @@ public class PlayerManager : MonoBehaviour
|
||||
{
|
||||
SceneManager.LoadScene(SceneManager.GetActiveScene().name, LoadSceneMode.Single);
|
||||
}
|
||||
|
||||
float hpInPrcent = (actualHealth / (health / 100.0f));
|
||||
guiManager.SetHealth((1.0f / 100.0f) * hpInPrcent);
|
||||
}
|
||||
|
||||
void FixedUpdate()
|
||||
@@ -223,11 +226,12 @@ 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)
|
||||
else if (hit.transform.gameObject.layer == LayerMask.NameToLayer("BuildPlace") && Input.GetKeyDown(KeyCode.E) && buildTime < Time.time && barricadeMaterials > 0)
|
||||
{
|
||||
BlockManager blockManager = spikes.GetComponent<BlockManager>();
|
||||
if (blockManager != null)
|
||||
{
|
||||
barricadeMaterials-=3;
|
||||
Instantiate<GameObject>(spikes, hit.point, transform.rotation);
|
||||
buildTime = buildRate + Time.time;
|
||||
}
|
||||
|
Reference in New Issue
Block a user