2024年2月14日发(作者:盖健柏)
public float minFlashDelay = 0.05f; public float maxFlashDelay = 2.0f; [Header("Total Delay")] //Time between ligthing effect //15 seconds default public float minDelay = 5.0f; public float maxDelay = 15.0f; //Total delay time float delay; //Delay time between lightning one //and lightning two float flashDelay; bool isWaiting = false; [Header("Background Color")] //Default background color public Color mainBackgroundColor; //Lightning background color public Color lightningBackgroundColor; [Header("Lightning Size")] //Minimum size of the lightning sprite public float minSize; //Maximum size of the lightning sprite public float maxSize; [Header("Components")] //Gun camera public Camera gunCamera; //The light component public Light lightObject; //Audio source public AudioSource lightningSound; //Array holding the lightning sprites public Sprite[] lightningSprites; //Sprite renderer public SpriteRenderer lightningSpriteRenderer; public AudioClip thunder; //Position and scale values for
//the lightning sprite renderer float x; float y; float z; Vector3 lightningPos; float lightningScale; private void Start () { //Make sure its off at start d = false; //Set the background color of the gun camera oundColor = mainBackgroundColor; } private void Update () { //Random value for how long the waiting should be delay = ( (minDelay, maxDelay)); //Random value for how long the delay between the flashes should be flashDelay = ( (minFlashDelay, maxFlashDelay)); //If is waiting is false, and the random value is 15 if (!isWaiting) {
if (!isWaiting) { //Start light flash one StartCoroutine (LightFlashOne ()); //Is waiting isWaiting = true; } } //First light flash private IEnumerator LightFlashOne () { //Enable the light d = true; //Set a random intensity value ity = ( (minIntensity, maxIntensity)); //Wait for set amount of time //Set the background color of the gun camera oundColor = lightningBackgroundColor; //Enable the lightning sprite renderer d = true; //Show a random lightning sprite from the array = lightningSprites
[ (0, )]; //Get random position for lightning sprite renderer x = (-150, 150); y = (55, 65); z = (300, 450); lightningPos = new Vector3 (x, y, z); //Choose random scale value lightningScale = (minSize, maxSize); //Move the sprite renderer to the new position on = lightningPos; ulerAngles = new Vector3(0, (0,360), 0); //Set the sprite renderer to the new scale cale = new Vector3
(lightningScale,lightningScale,lightningScale); yield return new WaitForSeconds (lightDuration); //Disable the light d = false; //Set the background color of the gun camera oundColor = mainBackgroundColor; //Disable the lightning sprite renderer d = false; //Start the flash delay StartCoroutine (FlashDelay ()); } //Delay between LightFlashOne one and LightFlashTwo private IEnumerator FlashDelay () { //Wait for set amount of time yield return new WaitForSeconds (flashDelay); //Start light flash two StartCoroutine (LightFlashTwo ()); } //Second light flash private IEnumerator LightFlashTwo () { //Enable the light d = true;
END
2024年2月14日发(作者:盖健柏)
public float minFlashDelay = 0.05f; public float maxFlashDelay = 2.0f; [Header("Total Delay")] //Time between ligthing effect //15 seconds default public float minDelay = 5.0f; public float maxDelay = 15.0f; //Total delay time float delay; //Delay time between lightning one //and lightning two float flashDelay; bool isWaiting = false; [Header("Background Color")] //Default background color public Color mainBackgroundColor; //Lightning background color public Color lightningBackgroundColor; [Header("Lightning Size")] //Minimum size of the lightning sprite public float minSize; //Maximum size of the lightning sprite public float maxSize; [Header("Components")] //Gun camera public Camera gunCamera; //The light component public Light lightObject; //Audio source public AudioSource lightningSound; //Array holding the lightning sprites public Sprite[] lightningSprites; //Sprite renderer public SpriteRenderer lightningSpriteRenderer; public AudioClip thunder; //Position and scale values for
//the lightning sprite renderer float x; float y; float z; Vector3 lightningPos; float lightningScale; private void Start () { //Make sure its off at start d = false; //Set the background color of the gun camera oundColor = mainBackgroundColor; } private void Update () { //Random value for how long the waiting should be delay = ( (minDelay, maxDelay)); //Random value for how long the delay between the flashes should be flashDelay = ( (minFlashDelay, maxFlashDelay)); //If is waiting is false, and the random value is 15 if (!isWaiting) {
if (!isWaiting) { //Start light flash one StartCoroutine (LightFlashOne ()); //Is waiting isWaiting = true; } } //First light flash private IEnumerator LightFlashOne () { //Enable the light d = true; //Set a random intensity value ity = ( (minIntensity, maxIntensity)); //Wait for set amount of time //Set the background color of the gun camera oundColor = lightningBackgroundColor; //Enable the lightning sprite renderer d = true; //Show a random lightning sprite from the array = lightningSprites
[ (0, )]; //Get random position for lightning sprite renderer x = (-150, 150); y = (55, 65); z = (300, 450); lightningPos = new Vector3 (x, y, z); //Choose random scale value lightningScale = (minSize, maxSize); //Move the sprite renderer to the new position on = lightningPos; ulerAngles = new Vector3(0, (0,360), 0); //Set the sprite renderer to the new scale cale = new Vector3
(lightningScale,lightningScale,lightningScale); yield return new WaitForSeconds (lightDuration); //Disable the light d = false; //Set the background color of the gun camera oundColor = mainBackgroundColor; //Disable the lightning sprite renderer d = false; //Start the flash delay StartCoroutine (FlashDelay ()); } //Delay between LightFlashOne one and LightFlashTwo private IEnumerator FlashDelay () { //Wait for set amount of time yield return new WaitForSeconds (flashDelay); //Start light flash two StartCoroutine (LightFlashTwo ()); } //Second light flash private IEnumerator LightFlashTwo () { //Enable the light d = true;
END