Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- C# Code:
- using UnityEngine;
- using System.Collections;
- public class CoroutinesExample : MonoBehaviour
- {
- void Update() {
- if (Input.GetKeyDown("f")) {
- StartCoroutine("Fade");
- }
- IEnumerator Fade() {
- for (float f = 1f; f >= 0; f -= 0.1f) {
- Color c = renderer.material.color;
- c.a = f; // alpha
- renderer.material.color = c;
- yield return;
- }
- }
- -----------------------------------
- F# Code:
- namespace CoroutinesExample
- open UnityEngine
- type CoroutinesExample() =
- inherit MonoBehaviour()
- member this.Update() =
- if Input.GetKey("f") then
- this.StartCoroutine("Fade")
- |> ignore
- member this.Fade() =
- seq { for f in 1.f .. -0.1f .. 0.f do
- let mutable c = this.renderer.material.color
- c.a <- f
- this.renderer.material.color <- c
- yield None }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement