Repair enemy
This commit is contained in:
@@ -8,6 +8,7 @@ public class BarricadeManager : MonoBehaviour
|
||||
public float health = 0;
|
||||
public List<GameObject> barricadePlanks = new List<GameObject>();
|
||||
public OffMeshLink offMeshLink;
|
||||
public Transform walkPoint;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
|
@@ -7,28 +7,45 @@ public class BlockManager : MonoBehaviour
|
||||
public enum BlockType {None, Barricade, Door, Wood, Ammo};
|
||||
public BlockType blockType = BlockType.None;
|
||||
public float health = 100;
|
||||
public float healthRate = 5;
|
||||
private float healthTime = 5;
|
||||
private Animation animation;
|
||||
private PlayerManager player;
|
||||
private bool action = false;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
player = FindObjectOfType<PlayerManager>();
|
||||
if (blockType == BlockType.Door)
|
||||
{
|
||||
animation = this.GetComponent<Animation>();
|
||||
}
|
||||
else if (blockType == BlockType.Wood)
|
||||
{
|
||||
healthTime = healthRate;
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (blockType == BlockType.Wood)
|
||||
{
|
||||
if (health < 100 && healthTime < Time.time)
|
||||
{
|
||||
health += 10;
|
||||
healthTime = healthRate + Time.time;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Action()
|
||||
{
|
||||
if (blockType == BlockType.Door)
|
||||
{
|
||||
if (!animation.isPlaying) {
|
||||
if (!animation.isPlaying)
|
||||
{
|
||||
if (!action)
|
||||
{
|
||||
animation["Door"].speed = 1;
|
||||
@@ -42,7 +59,14 @@ public class BlockManager : MonoBehaviour
|
||||
action = false;
|
||||
}
|
||||
animation.Play("Door");
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (blockType == BlockType.Wood)
|
||||
{
|
||||
if (health > 0 && player.barricadeMaterials < 50) {
|
||||
health -= 10;
|
||||
player.barricadeMaterials += (player.barricadeMaterials <= 40 ? 10 : (50 - player.barricadeMaterials));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -12,7 +12,7 @@ public class EnemyManager : MonoBehaviour
|
||||
public float actualHealth;
|
||||
private NavMeshAgent navMeshAgent;
|
||||
private PlayerManager player;
|
||||
private BarricadeManager barricadeManager;
|
||||
public BarricadeManager barricadeManager;
|
||||
public List<GameObject> bodyParts = new List<GameObject>();
|
||||
|
||||
// Start is called before the first frame update
|
||||
@@ -34,29 +34,33 @@ public class EnemyManager : MonoBehaviour
|
||||
}
|
||||
DestroyBarricades();
|
||||
Attack();
|
||||
|
||||
if (navMeshAgent != null && barricadeManager == null)
|
||||
{
|
||||
navMeshAgent.SetDestination(player.transform.position);
|
||||
}
|
||||
else if (navMeshAgent != null && barricadeManager != null)
|
||||
{
|
||||
navMeshAgent.SetDestination(barricadeManager.transform.position);
|
||||
navMeshAgent.SetDestination(new Vector3(barricadeManager.walkPoint.position.x, 0, barricadeManager.walkPoint.position.z));
|
||||
}
|
||||
}
|
||||
|
||||
void FixedUpdate()
|
||||
{
|
||||
if (actualHealth > 0 && barricadeManager == null)
|
||||
if (navMeshAgent.pathStatus == NavMeshPathStatus.PathComplete)
|
||||
{
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,27 +75,29 @@ public class EnemyManager : MonoBehaviour
|
||||
void DestroyBarricades()
|
||||
{
|
||||
NavMeshPath path = new NavMeshPath();
|
||||
navMeshAgent.CalculatePath(player.transform.position, path);
|
||||
if (path.status == NavMeshPathStatus.PathPartial)
|
||||
{
|
||||
BarricadeManager[] barricadeManagers = FindObjectsOfType<BarricadeManager>();
|
||||
foreach(BarricadeManager localBarricadeManager in barricadeManagers)
|
||||
if (navMeshAgent != null) {
|
||||
navMeshAgent.CalculatePath(player.transform.position, path);
|
||||
if (path.status == NavMeshPathStatus.PathPartial)
|
||||
{
|
||||
if (barricadeManager == null)
|
||||
BarricadeManager[] barricadeManagers = GameObject.FindObjectsOfType<BarricadeManager>();
|
||||
foreach (BarricadeManager localBarricadeManager in barricadeManagers)
|
||||
{
|
||||
barricadeManager = localBarricadeManager;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (localBarricadeManager.health <= 0 || Vector3.Distance(barricadeManager.transform.position, transform.position) > Vector3.Distance(localBarricadeManager.transform.position, transform.position)) {
|
||||
if (barricadeManager == null)
|
||||
{
|
||||
barricadeManager = localBarricadeManager;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (localBarricadeManager.health < barricadeManager.health || Vector3.Distance(barricadeManager.transform.position, transform.position) > Vector3.Distance(localBarricadeManager.transform.position, transform.position)) {
|
||||
barricadeManager = localBarricadeManager;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
barricadeManager = null;
|
||||
else
|
||||
{
|
||||
barricadeManager = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,21 +153,22 @@ public class EnemyManager : MonoBehaviour
|
||||
void Attack()
|
||||
{
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(transform.position + new Vector3(0,1f,0),transform.forward,out hit,2) && attackTime <= Time.time)
|
||||
if (Physics.Raycast(transform.position + new Vector3(0,0.5f,0),transform.forward,out hit,3) && attackTime <= Time.time)
|
||||
{
|
||||
if (hit.transform.CompareTag("Player"))
|
||||
{
|
||||
player.Damage(damage);
|
||||
attackTime = attackRate + Time.time;
|
||||
}
|
||||
else if (hit.transform.CompareTag("BarricadeField"))
|
||||
if (hit.transform.CompareTag("BarricadeField"))
|
||||
{
|
||||
BarricadeManager barricadeManager = hit.transform.GetComponent<BarricadeManager>();
|
||||
if (barricadeManager != null)
|
||||
{
|
||||
barricadeManager.Damage(damage);
|
||||
attackTime = attackRate + Time.time;
|
||||
}
|
||||
}
|
||||
attackTime = attackRate + Time.time;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -12,7 +12,7 @@ public class PlayerManager : MonoBehaviour
|
||||
public float mouseSensitive = 200;
|
||||
public float buildRate = 0.5f;
|
||||
public float health = 100;
|
||||
private float actualHealth = 100;
|
||||
public float actualHealth = 100;
|
||||
private float buildTime;
|
||||
private bool run = false;
|
||||
private Camera playerCamera;
|
||||
@@ -186,13 +186,17 @@ public class PlayerManager : MonoBehaviour
|
||||
{
|
||||
BarricadeManager barricadeManager = hit.transform.GetComponent<BarricadeManager>();
|
||||
barricadeManager.addPlank();
|
||||
//barricadeMaterials--; //než bude jistota že uděláme zbírání materiálu
|
||||
barricadeMaterials--;
|
||||
buildTime = buildRate + Time.time;
|
||||
}
|
||||
if (Input.GetAxisRaw("Build") > 0 && hit.transform.tag == "Interact")
|
||||
{
|
||||
}
|
||||
if (Input.GetKeyDown(KeyCode.E) && hit.transform.tag == "Interact")
|
||||
{
|
||||
BlockManager blockManager = hit.transform.GetComponent<BlockManager>();
|
||||
blockManager.Action();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user