Import first minecraft scene + other scripts fixes
This commit is contained in:
parent
1165e50bb5
commit
6a897fabfc
103 changed files with 273043 additions and 45 deletions
|
@ -7,7 +7,8 @@ public class AttackHandler : MonoBehaviour
|
|||
[SerializeField] private float damage;
|
||||
[SerializeField] private float cooldown;
|
||||
[SerializeField] private Collider attackShape;
|
||||
|
||||
[SerializeField] private float knockback;
|
||||
|
||||
private float _timer;
|
||||
|
||||
void Start()
|
||||
|
@ -19,19 +20,27 @@ public class AttackHandler : MonoBehaviour
|
|||
{
|
||||
_timer = Mathf.Max(_timer - Time.deltaTime, 0f);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Launch an Attack, and return true if it's possible to attack
|
||||
/// see what Units are in the attackShape, apply damage and knockback to those unit
|
||||
/// </summary>
|
||||
public bool Attack()
|
||||
{
|
||||
if (_timer >= 0) return false;
|
||||
|
||||
Collider[] targets = DetectTargets();
|
||||
foreach (Collider target in targets)
|
||||
{
|
||||
if (!target.CompareTag("Unit")) continue;
|
||||
// GetComponent is expensive in performance, optimize here if it's slow
|
||||
Unit unit = target.GetComponent<Unit>();
|
||||
unit.healthHandler.TakeDamage(damage);
|
||||
unit.Health.TakeDamage(damage);
|
||||
Vector3 knockbackVector = knockback * (target.transform.position - transform.position).normalized;
|
||||
unit.Body.AddForce(knockbackVector, ForceMode.Impulse);
|
||||
|
||||
}
|
||||
_timer = cooldown;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ public class HealthHandler : MonoBehaviour
|
|||
{
|
||||
Debug.Assert(damage >= 0, "Damage cannot be negative, use Heal if you want to heal");
|
||||
currentHealth -= Mathf.Max(0, damage-armor);
|
||||
if (currentHealth <= 0) Death();
|
||||
}
|
||||
|
||||
public void Heal(float value)
|
||||
|
@ -34,5 +35,10 @@ public class HealthHandler : MonoBehaviour
|
|||
Debug.Assert(armorBoost >= 0, "armorBoost can't be less than zero, use EquipArmor instead");
|
||||
armor -= armorBoost;
|
||||
}
|
||||
|
||||
public void Death()
|
||||
{
|
||||
print("you dead");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,16 +4,16 @@ using UnityEngine;
|
|||
|
||||
public class Unit : MonoBehaviour
|
||||
{
|
||||
[SerializeField] public HealthHandler healthHandler;
|
||||
[SerializeField] public AttackHandler attackHandler;
|
||||
[field: SerializeField] public Rigidbody Body { get; private set; }
|
||||
[field: SerializeField] public HealthHandler Health { get; private set; }
|
||||
[field: SerializeField] public AttackHandler Attack { get; private set; }
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Null safety enjoyers things
|
||||
Debug.Assert(healthHandler != null);
|
||||
Debug.Assert(attackHandler != null);
|
||||
|
||||
Debug.Assert(Body != null);
|
||||
Debug.Assert(Health != null);
|
||||
Debug.Assert(Attack != null);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue