next push
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
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;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
@@ -21,12 +22,22 @@ public class BarricadeManager : MonoBehaviour
|
||||
{
|
||||
health = 0;
|
||||
}
|
||||
|
||||
if (health <= 0)
|
||||
{
|
||||
offMeshLink.enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
offMeshLink.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void addPlank()
|
||||
{
|
||||
if (health < (barricadePlanks.Count * 10)) {
|
||||
health += 10;
|
||||
offMeshLink.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -7,7 +7,7 @@ public class BlockManager : MonoBehaviour
|
||||
public enum BlockType {None, Barricade, Door, Wood, Ammo};
|
||||
public BlockType blockType = BlockType.None;
|
||||
public float health = 100;
|
||||
private Animator animator;
|
||||
private Animation animation;
|
||||
private bool action = false;
|
||||
|
||||
// Start is called before the first frame update
|
||||
@@ -15,7 +15,7 @@ public class BlockManager : MonoBehaviour
|
||||
{
|
||||
if (blockType == BlockType.Door)
|
||||
{
|
||||
animator = this.GetComponent<Animator>();
|
||||
animation = this.GetComponent<Animation>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,18 +28,21 @@ public class BlockManager : MonoBehaviour
|
||||
{
|
||||
if (blockType == BlockType.Door)
|
||||
{
|
||||
if (!action)
|
||||
{
|
||||
this.GetComponent<BoxCollider>().isTrigger = true;
|
||||
action = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.GetComponent<BoxCollider>().isTrigger = false;
|
||||
action = false;
|
||||
}
|
||||
animator.ResetTrigger("Door");
|
||||
animator.SetTrigger("Door");
|
||||
if (!animation.isPlaying) {
|
||||
if (!action)
|
||||
{
|
||||
animation["Door"].speed = 1;
|
||||
animation["Door"].time = 0;
|
||||
action = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
animation["Door"].speed = -1;
|
||||
animation["Door"].time = animation["Door"].length;
|
||||
action = false;
|
||||
}
|
||||
animation.Play("Door");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -9,7 +9,7 @@ public class EnemyManager : MonoBehaviour
|
||||
public float damage = 10;
|
||||
public float attackRate = 2;
|
||||
private float attackTime = 2;
|
||||
private float actualHealth;
|
||||
public float actualHealth;
|
||||
private NavMeshAgent navMeshAgent;
|
||||
private PlayerManager player;
|
||||
private BarricadeManager barricadeManager;
|
||||
@@ -30,10 +30,10 @@ public class EnemyManager : MonoBehaviour
|
||||
DropBodyPart();
|
||||
if (actualHealth <= 0)
|
||||
{
|
||||
Destroy(this.gameObject);
|
||||
Destroy(transform.gameObject, 0.1f);
|
||||
}
|
||||
DestroyBarricades();
|
||||
|
||||
Attack();
|
||||
if (navMeshAgent != null && barricadeManager == null)
|
||||
{
|
||||
navMeshAgent.SetDestination(player.transform.position);
|
||||
@@ -70,8 +70,9 @@ public class EnemyManager : MonoBehaviour
|
||||
|
||||
void DestroyBarricades()
|
||||
{
|
||||
Debug.Log(navMeshAgent.pathPending);
|
||||
if (navMeshAgent.pathStatus == NavMeshPathStatus.PathInvalid)
|
||||
NavMeshPath path = new NavMeshPath();
|
||||
navMeshAgent.CalculatePath(player.transform.position, path);
|
||||
if (path.status == NavMeshPathStatus.PathPartial)
|
||||
{
|
||||
BarricadeManager[] barricadeManagers = FindObjectsOfType<BarricadeManager>();
|
||||
foreach(BarricadeManager localBarricadeManager in barricadeManagers)
|
||||
@@ -82,38 +83,61 @@ public class EnemyManager : MonoBehaviour
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Vector3.Distance(barricadeManager.transform.position, transform.position) > Vector3.Distance(localBarricadeManager.transform.position, transform.position)) {
|
||||
if (localBarricadeManager.health <= 0 || Vector3.Distance(barricadeManager.transform.position, transform.position) > Vector3.Distance(localBarricadeManager.transform.position, transform.position)) {
|
||||
barricadeManager = localBarricadeManager;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
barricadeManager = null;
|
||||
}
|
||||
}
|
||||
|
||||
void DropBodyPart()
|
||||
{
|
||||
if (bodyParts.Count > 0)
|
||||
{
|
||||
float number = health / (bodyParts.Count + 1);
|
||||
float number = health / bodyParts.Count;
|
||||
for (int i = 0; i < bodyParts.Count; i++)
|
||||
{
|
||||
if ((health - actualHealth) / number > i)
|
||||
if (bodyParts.Count - 1 != i)
|
||||
{
|
||||
if (bodyParts[i] != null && bodyParts[i].transform.parent != null) {
|
||||
bodyParts[i].transform.parent = null;
|
||||
bodyParts[i].AddComponent<Rigidbody>();
|
||||
Rigidbody rigidBodyEnemy = bodyParts[i].GetComponent<Rigidbody>() as Rigidbody;
|
||||
bodyParts[i].AddComponent<MeshCollider>();
|
||||
MeshCollider meshCollider = bodyParts[i].GetComponent<MeshCollider>() as MeshCollider;
|
||||
meshCollider.convex = true;
|
||||
if (i == bodyParts.Count - 1) {
|
||||
if ((health - actualHealth) / number > i)
|
||||
{
|
||||
if (bodyParts[i] != null && bodyParts[i].transform.parent != null)
|
||||
{
|
||||
bodyParts[i].transform.parent = null;
|
||||
bodyParts[i].AddComponent<Rigidbody>();
|
||||
Rigidbody rigidBodyEnemy = bodyParts[i].GetComponent<Rigidbody>() as Rigidbody;
|
||||
bodyParts[i].AddComponent<MeshCollider>();
|
||||
MeshCollider meshCollider = bodyParts[i].GetComponent<MeshCollider>() as MeshCollider;
|
||||
meshCollider.convex = true;
|
||||
rigidBodyEnemy.mass = 10 * bodyParts.Count;
|
||||
Destroy(bodyParts[i], 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (actualHealth == 0)
|
||||
{
|
||||
if (bodyParts[i] != null && bodyParts[i].transform.parent != null)
|
||||
{
|
||||
bodyParts[i].transform.parent = null;
|
||||
bodyParts[i].AddComponent<Rigidbody>();
|
||||
Rigidbody rigidBodyEnemy = bodyParts[i].GetComponent<Rigidbody>() as Rigidbody;
|
||||
bodyParts[i].AddComponent<MeshCollider>();
|
||||
MeshCollider meshCollider = bodyParts[i].GetComponent<MeshCollider>() as MeshCollider;
|
||||
meshCollider.convex = true;
|
||||
navMeshAgent.isStopped = true;
|
||||
navMeshAgent.enabled = false;
|
||||
navMeshAgent = null;
|
||||
rigidBodyEnemy.velocity = bodyParts[i].transform.forward;
|
||||
rigidBodyEnemy.mass = 10 * bodyParts.Count;
|
||||
Destroy(bodyParts[i], 4);
|
||||
}
|
||||
rigidBodyEnemy.mass = 10 * bodyParts.Count;
|
||||
Destroy(bodyParts[i], 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -123,7 +147,7 @@ public class EnemyManager : MonoBehaviour
|
||||
void Attack()
|
||||
{
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(transform.position + new Vector3(0,1,0),transform.forward,out hit,2) && attackTime <= Time.time)
|
||||
if (Physics.Raycast(transform.position + new Vector3(0,1f,0),transform.forward,out hit,2) && attackTime <= Time.time)
|
||||
{
|
||||
if (hit.transform.CompareTag("Player"))
|
||||
{
|
||||
@@ -137,6 +161,7 @@ public class EnemyManager : MonoBehaviour
|
||||
barricadeManager.Damage(damage);
|
||||
}
|
||||
}
|
||||
attackTime = attackRate + Time.time;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -180,7 +180,7 @@ public class PlayerManager : MonoBehaviour
|
||||
{
|
||||
Ray ray = playerCamera.ScreenPointToRay(Input.mousePosition);
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(ray, out hit, 1))
|
||||
if (Physics.Raycast(ray, out hit, 2))
|
||||
{
|
||||
if (Input.GetAxisRaw("Build") > 0 && buildTime < Time.time && barricadeMaterials > 0 && hit.transform.tag == "BarricadeField")
|
||||
{
|
||||
|
Reference in New Issue
Block a user