topical media & game development

talk show tell print

lib-unity-presentation-Assets-Scripts-Billboard.cs / cs



  using UnityEngine;
  using System.Collections;
  
  public class Billboard : MonoBehaviour {
  
      public Texture2D slide;
  
          void Awake () {
          Renderer ren = transform.GetComponentInChildren<Renderer>();
          ren.materials[1].mainTexture = slide;
          this.useGUILayout = false;
  
          }
  
      void OnGUI()
      {
          if (visible)
          {
              if (Time.frameCount <= 5) displayPercent = 1;
              displayPercent += Time.deltaTime * 3;
          }
          else if (displayPercent > 0)
          {
              displayPercent -= Time.deltaTime * 3;                  
          }
  
          if (displayPercent > 0)
          {
              displayPercent = Mathf.Clamp01(displayPercent);
              float w = Screen.width * displayPercent;
              float h = Screen.height * displayPercent;
              Rect rect = new Rect((Screen.width / 2 - w / 2), (Screen.height / 2 - h / 2), w, h);
              GUI.DrawTexture(rect, slide, ScaleMode.ScaleToFit);
          }
      }
  
      private bool visible = false;
      private float displayPercent = 0;
  
      void OnTriggerEnter (Collider other ) {
          if (other.transform.tag == "Player")
          {
              displayPercent = 0;
              visible = true;
          }
      }
      void OnTriggerExit(Collider other)
      {
          if (other.transform.tag == "Player")
          {
              visible = false;
          }
      }
  
  }
  


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.