制作水果忍者-JS-1

来源:互联网 发布:淘宝卖怎样充值话费 编辑:程序博客网 时间:2024/04/30 13:06

看着这位老师的视频写的:http://www.kokojia.com/course-3421.html

他是C#我写的JS;

记录一下我写的过程方便回忆

先是制作背景,然后学到了一个制作UGUI很重要的九宫格,这个很方便去制作背景图片的大小。

利用这个圆形透明背景图片制作出这两种大小不一样背景(文字是自己添加的);


然后制作read go 的开始提示。

#pragma strictimport UnityEngine.UI;var speed:float=0.5;var speed1:float=0.3;var color:Color;var text:Text;var color1:Color;var shadow:Shadow;var i:int=10;function Start () {color = GetComponent(Text).color;text = GetComponent(Text);color1 =  GetComponent(Shadow).effectColor;shadow = GetComponent(Shadow);}function Update () {if(gameObject.activeSelf){color.a -= Time.deltaTime * speed;text.color=color;color1.a -= Time.deltaTime * speed1;shadow.effectColor = color1;}}
上面是制作read go的渐渐隐藏效果;

下面是让read go 在不同时间里出现和消失

var ready:GameObject;var go:GameObject;function Start () {yield WaitForSeconds(2);ready.SetActive(true);yield  WaitForSeconds(2);ready.SetActive(false);go.SetActive(true);yield  WaitForSeconds(2);go.SetActive(false);
然后是制作倒计时,从30秒开始倒计时,计算分数下次再弄;

#pragma strictimport UnityEngine.UI;var showTime:float=0;//显示时间var timeavilable:float=30;//可用时间30svar starttime:float=0;//开始时间var time:float=0;var run:boolean=false;//运行参数var pause:boolean=false;var showTimeLeft:boolean=true;var timestr:String=String.Empty;var text:Text; function runtime(){run=true;starttime=Time.time;//记录开始时间}function Start () {yield WaitForSeconds(6);//为了readygo消失开始计时runtime();}function Update () {if(run){time = Time.time - starttime;}if(showTimeLeft){showTime = timeavilable - time;if(showTime <= 0){showTime = 0;}}var minutes:int = parseInt(showTime/60);var second:int = parseInt(showTime%60);var fraction:int = parseInt((showTime*100)%100);timestr = String.Format("{0:00}:{1:00}:{2:00}",minutes,second,fraction);text.text = "Time" + timestr;}

思想:显示利用start记录开始的时间,然后一直调用当前的时间,用当前的时间减去开始的时间就是所花费的时间,当小于0时就让showtime显示时间变为0,然后将showtime由10进制的值变为时间值,然后利用String.Format自定义格式来输出。

制作后的效果:

运用后:


会倒计时:

学到的东西:制作UGUI背景的九宫格,然后是JS的自定义格式和C#的自定义格式几乎一样(我目前知道的);

问题:途中发现了JS的静态函数不会写。


0 0
原创粉丝点击