Advertisement
Guest User

Untitled

a guest
Nov 6th, 2013
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. C# Code:
  2.  
  3. using UnityEngine;
  4. using System.Collections;
  5.  
  6. public class CoroutinesExample : MonoBehaviour
  7. {
  8.     void Update() {
  9.         if (Input.GetKeyDown("f")) {
  10.         StartCoroutine("Fade");
  11.     }
  12.  
  13.     IEnumerator Fade() {
  14.         for (float f = 1f; f >= 0; f -= 0.1f) {
  15.             Color c = renderer.material.color;
  16.             c.a = f; // alpha
  17.             renderer.material.color = c;
  18.             yield return;
  19.         }
  20.     }
  21.  
  22. -----------------------------------
  23.  
  24. F# Code:
  25.  
  26. namespace CoroutinesExample
  27. open UnityEngine
  28.  
  29. type CoroutinesExample() =
  30.     inherit MonoBehaviour()
  31.    
  32.     member this.Update() =
  33.         if Input.GetKey("f") then
  34.             this.StartCoroutine("Fade")
  35.             |> ignore
  36.  
  37.     member this.Fade() =
  38.         seq { for f in 1.f .. -0.1f .. 0.f do
  39.             let mutable c = this.renderer.material.color
  40.             c.a <- f
  41.             this.renderer.material.color <- c
  42.             yield None }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement