Homebound / Scripts / InteractionsAndObstacles / WindHazard.cs
WindHazard.cs
Raw
using UnityEngine;

/// <summary>
/// Wind Obstacle that is attached to an object with a collider to push the player in the direction indicated off the aspects
/// </summary>
public class WindHazard : MonoBehaviour
{
    [Tooltip("The strength of the wind's power in the direction the object is blowing")]
    public float strengthOfWind         = 1.0f;                                             // Power of the wind
    [Tooltip("The direction of which the wind is blowing")]
    public Vector3 directionOfWind      = Vector3.down;                                     // Direction of the wind
    [Tooltip("The randomness of which the pulses and wind will blow in the direction set")]
    [Range(0f, 5f)]
    public float turbulence             = 1.0f;                                             // Randomness of the gusts of wind
    [Tooltip("The normal time wind pulses will be sent out in the direction")]
    [Range(0f, 4f)]
    public float windPulse              = 0.5f;                                             // General pulse time for the wind gusts

    /// <summary>
    /// Pulse is calculated after each gust the player is hit by
    /// </summary>
    public void CalculateTurbulence()
    {
        windPulse = Random.Range(Mathf.Clamp(windPulse - turbulence, .33f, 5.0f), windPulse + turbulence);
    }
    // Draws an arrow in the direction of the wind blowing
    void OnDrawGizmos()
    {
        if (directionOfWind.magnitude != 0)
            DrawArrow.ForGizmo(transform.position, directionOfWind, Color.yellow);
    }
}