You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.1 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class WaterController : MonoBehaviour {
  5. #region Unity Functions
  6. // Use this for initialization
  7. void Start() {
  8. }
  9. // Update is called once per frame
  10. void Update() {
  11. }
  12. #endregion Unity Fucntions
  13. #region Interaction Functions
  14. /// <summary>
  15. /// Pushes any objects in water away from this point
  16. /// </summary>
  17. /// <param name="point"> point where water is createds</param>
  18. /// <param name="radius"> radius of effected object</param>
  19. /// <param name="power"> power with chich the objects are pushed</param>
  20. public void CreateWave(Vector3 point, float radius, float power){
  21. //find all colliders within the wave distance
  22. Collider[] colliders = Physics.OverlapSphere(point, radius);
  23. foreach (Collider hit in colliders) {
  24. Rigidbody rb = hit.GetComponent<Rigidbody>();
  25. if (rb != null)
  26. rb.AddExplosionForce(power, point, radius, 0.0f);
  27. }
  28. #endregion Interaction Functions
  29. }
  30. #region Collision Functions
  31. void OnTriggerEnter(Collider other) {
  32. //calls appropriate function if the object should interact with the water on enter
  33. WaterObject waterInteraction = other.gameObject.GetComponent<WaterObject>();
  34. if (waterInteraction != null) {
  35. waterInteraction.OnWaterEnter();
  36. }
  37. }
  38. void OnTriggerStay(Collider other) {
  39. //calls appropriate function if the object should interact with the water on stay
  40. WaterObject waterInteraction = other.gameObject.GetComponent<WaterObject>();
  41. if (waterInteraction != null) {
  42. waterInteraction.OnWaterStay();
  43. }
  44. }
  45. void OnTriggerExit(Collider other) {
  46. //calls appropriate function if the object should interact with the water on exit
  47. WaterObject waterInteraction = other.gameObject.GetComponent<WaterObject>();
  48. if (waterInteraction != null) {
  49. waterInteraction.OnWaterExit();
  50. }
  51. }
  52. #endregion Collision Functions
  53. }