BallTrigger.cs 1005 B

12345678910111213141516171819202122232425262728293031323334
  1. //======= Copyright (c) Stereolabs Corporation, All rights reserved. ===============
  2. using UnityEngine;
  3. /// <summary>
  4. /// Previously used in the ZED spatial mapping sample scene.
  5. /// Sends events when the ball the script is attached to has touched an object.
  6. /// </summary>
  7. public class BallTrigger : MonoBehaviour
  8. {
  9. private Rigidbody body;
  10. private bool hasDamaged = false;
  11. private const float dammage = 1.0f;
  12. private const float minVelocityDammage = 5;
  13. private void Start()
  14. {
  15. body = GetComponent<Rigidbody>();
  16. }
  17. public void ResetValues()
  18. {
  19. hasDamaged = false;
  20. }
  21. void OnTriggerEnter(Collider other)
  22. {
  23. if (hasDamaged || body.velocity.magnitude < minVelocityDammage) return;
  24. if (other.gameObject.name.Contains("ZomBunny"))
  25. {
  26. hasDamaged = true;
  27. other.gameObject.GetComponent<EnemyBehavior>().Dammage(dammage * body.velocity.magnitude);
  28. }
  29. }
  30. }