using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WaterController : MonoBehaviour {
#region Unity Functions
// Use this for initialization
void Start() {
}
// Update is called once per frame
void Update() {
}
#endregion Unity Fucntions
#region Interaction Functions
///
/// Pushes any objects in water away from this point
///
/// point where water is createds
/// radius of effected object
/// power with chich the objects are pushed
public void CreateWave(Vector3 point, float radius, float power){
//find all colliders within the wave distance
Collider[] colliders = Physics.OverlapSphere(point, radius);
foreach (Collider hit in colliders) {
Rigidbody rb = hit.GetComponent();
if (rb != null)
rb.AddExplosionForce(power, point, radius, 0.0f);
}
#endregion Interaction Functions
}
#region Collision Functions
void OnTriggerEnter(Collider other) {
//calls appropriate function if the object should interact with the water on enter
WaterObject waterInteraction = other.gameObject.GetComponent();
if (waterInteraction != null) {
waterInteraction.OnWaterEnter();
}
}
void OnTriggerStay(Collider other) {
//calls appropriate function if the object should interact with the water on stay
WaterObject waterInteraction = other.gameObject.GetComponent();
if (waterInteraction != null) {
waterInteraction.OnWaterStay();
}
}
void OnTriggerExit(Collider other) {
//calls appropriate function if the object should interact with the water on exit
WaterObject waterInteraction = other.gameObject.GetComponent();
if (waterInteraction != null) {
waterInteraction.OnWaterExit();
}
}
#endregion Collision Functions
}