打雷腳本

using UnityEngine;
using System.Collections;

public class Thundering : MonoBehaviour
{
    public Transform ground;

    float groundWidth, groundlength;

    Light thunderLight;

    

    public float maxThunderDur;
    float thunderDuration;

    public float maxThunderBreakDur;
    float thunderBreakDuration;

    public float maxThunderRestDur;
    float thunderRestDur;

    int serialThunderTime;
    public int maxSerialThunderTime;

    void Awake()
    {
        thunderLight = GetComponent<Light>();
    }

    // Use this for initialization
    void Start()
    {
        StartCoroutine(Thunder());
    }

    IEnumerator Thunder()
    {
        while (true)
        {
            serialThunderTime = Random.Range(0, maxSerialThunderTime + 1);
            for (int i = 0; i < serialThunderTime; i++)
            {
                thunderDuration = Random.Range(0, maxThunderDur);
                thunderLight.intensity = 8f;
                yield return new WaitForSeconds(thunderDuration);

                thunderLight.intensity = 2f;
                thunderBreakDuration = Random.Range(0, maxThunderBreakDur);
                yield return new WaitForSeconds(thunderBreakDuration);
            }

            thunderRestDur = Random.Range(0, maxThunderRestDur);
            yield return new WaitForSeconds(maxThunderRestDur);
        }
    }

 
}


下面是參數設置:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章