按键控制GUI键入脚本.docxVIP

  • 2
  • 0
  • 约1.33千字
  • 约 2页
  • 2020-06-11 发布于山东
  • 举报
按键控制GUI键入脚本 Posted on 2013年05月27日 by U3d / \o 查看 Unity3D脚本/插件 中的全部文章 Unity3D脚本/插件/被围观 15 次 单击按键“A”(随意改变),可以控制GUIText马上显示出来,然后淡出;按住按键“A”,可以使GUIText淡入,如果抬起按键则淡出。 01 var fadeSpeed : float=0.5;//透明度变化的速度 02 03   private var StartTime : float=1;//最开始的等待时间 04 05   private var timeLeft:float=0.5;//流逝的时间 06 07   function Awake () { 08 09   timeLeft = fadeSpeed;Unity3D教程手册 10 11   } 12 13   function Update () { 14 15   if (StartTime 0){ 16 17   StartTime = StartTime -Time.deltaTime; 18 19   } else { 20 21   if (Input.GetKey(KeyCode.A)){//随便定义一个按键 22 23   fade(true); 24 25   }else{ 26 27   fade(false); 28 29   } 30 31   } 32 33   } 34 35   function fade(direction:boolean){ 36 37   var alpha; 38 39   if (direction){ 40 41   if (guiText.material.color.a 1){ 42 43   timeLeft = timeLeft - Time.deltaTime; 44 45   alpha = (timeLeft/fadeSpeed);//利用时间的比例来确定阿尔法的值 46 47   guiText.material.color.a=1-alpha; 48 49   } else { 50 51   timeLeft = fadeSpeed; 52 53   } 54 55   } else { 56 57   if (guiText.material.color.a 0){ 58 59   timeLeft = timeLeft - Time.deltaTime; 60 61   alpha = (timeLeft/fadeSpeed); 62 63   guiText.material.color.a=alpha; 64 65   } else { 66 67   timeLeft = fadeSpeed; 68 69   } 70 71   } 72 73   }

文档评论(0)

1亿VIP精品文档

相关文档