|
|
@ -0,0 +1,75 @@ |
|
|
|
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
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Pushes any objects in water away from this point
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="point"> point where water is createds</param>
|
|
|
|
/// <param name="radius"> radius of effected object</param>
|
|
|
|
/// <param name="power"> power with chich the objects are pushed</param>
|
|
|
|
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<Rigidbody>(); |
|
|
|
|
|
|
|
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<WaterObject>(); |
|
|
|
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<WaterObject>(); |
|
|
|
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<WaterObject>(); |
|
|
|
if (waterInteraction != null) { |
|
|
|
waterInteraction.OnWaterExit(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
#endregion Collision Functions
|
|
|
|
|
|
|
|
|
|
|
|
} |