Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. [RequireComponent(typeof(Animator))]
  4. [RequireComponent(typeof(SphereCollider))]
  5. public abstract class AEnemy : MonoBehaviour
  6. {
  7. [SerializeField] private float _viewDistance = default;
  8. protected float ViewDistance => _viewDistance;
  9. [SerializeField] private float _viewAngle = default;
  10. protected float ViewAngle => _viewAngle;
  11.  
  12. [SerializeField] private int _startingLife = default;
  13. protected int life = default;
  14.  
  15. [SerializeField] private Light _light = default;
  16.  
  17. protected Animator animator = default;
  18.  
  19. public abstract void OnDamaged();
  20. public abstract void Die();
  21. public abstract void OnAlert();
  22. public abstract void OnBait();
  23.  
  24. protected abstract void OnViewZombie(AZombie zombie);
  25.  
  26. protected void Start()
  27. {
  28. life = _startingLife;
  29.  
  30. _light.range = ViewDistance;
  31. _light.spotAngle = ViewAngle;
  32.  
  33. animator = GetComponent<Animator>();
  34.  
  35. var sc = GetComponent<SphereCollider>();
  36. Debug.Log($"Sphere Collider: {sc}");
  37. sc.radius = ViewDistance;
  38. }
  39.  
  40. protected void OnTriggerStay(Collider other)
  41. {
  42. AZombie zombie = other.transform.GetComponent<AZombie>();
  43. if (zombie == null)
  44. return;
  45. Vector3 distanceVector = zombie.transform.position - transform.position;
  46. if (!Physics.Raycast(transform.position, distanceVector, out RaycastHit hit, ViewDistance))
  47. return;
  48. if (hit.transform.GetComponent<AZombie>() == null)
  49. return;
  50. OnViewZombie(zombie);
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement