unity3d中使用Ngui实现幻灯片效果
2013-04-10 22:33
489 查看
首先添加一个Simple Texture用来当做幻灯片的对象。
新建一个材质,着色器选择如图
在Simple Texture上选择我们刚刚建立的材质
最后上代码
using UnityEngine;
using System.Collections;
public class SlideShow : MonoBehaviour
{
public float waitTime;
float tm;
//TweenColor tc;
bool isshow = false;
TweenColor[] tcs;
public string url;
public int count;
int index=0;
void Start ()
{
this.gameObject.AddComponent<TweenColor> ();
this.gameObject.AddComponent<TweenColor> ();
tcs = GetComponents<TweenColor> ();
tcs [0].enabled = false;
tcs [1].enabled = false;
tcs [0].from = new Color (1, 1, 1, 1);
tcs [0].to = new Color (1, 1, 1, 0);
tcs [1].from = new Color (1, 1, 1, 0);
tcs [1].to = new Color (1, 1, 1, 1);
tcs [0].eventReceiver = this.gameObject;
tcs [0].callWhenFinished = "endChange";
tcs [0].duration = 1;
tcs [1].duration = 1;
}
// Update is called once per frame
void Update ()
{
tm += Time.deltaTime;
if (tm > waitTime) {
if(index<count-1)
{
index++;
}
else
{
index=0;
}
startChange ();
tm = 0;
}
}
void startChange ()
{
tcs [0].Reset ();
tcs [0].enabled = true;
Debug.Log ("Start");
}
void endChange ()
{
UITexture ut=GetComponent<UITexture>();
ut.material.mainTexture=Resources.Load(url+index.ToString()) as Texture;
tcs [1].Reset ();
tcs [1].enabled = true;
}
}
填写参数,完成!~
来自为知笔记(Wiz)Time=2013-04-02 14:55:52
新建一个材质,着色器选择如图
在Simple Texture上选择我们刚刚建立的材质
最后上代码
using UnityEngine;
using System.Collections;
public class SlideShow : MonoBehaviour
{
public float waitTime;
float tm;
//TweenColor tc;
bool isshow = false;
TweenColor[] tcs;
public string url;
public int count;
int index=0;
void Start ()
{
this.gameObject.AddComponent<TweenColor> ();
this.gameObject.AddComponent<TweenColor> ();
tcs = GetComponents<TweenColor> ();
tcs [0].enabled = false;
tcs [1].enabled = false;
tcs [0].from = new Color (1, 1, 1, 1);
tcs [0].to = new Color (1, 1, 1, 0);
tcs [1].from = new Color (1, 1, 1, 0);
tcs [1].to = new Color (1, 1, 1, 1);
tcs [0].eventReceiver = this.gameObject;
tcs [0].callWhenFinished = "endChange";
tcs [0].duration = 1;
tcs [1].duration = 1;
}
// Update is called once per frame
void Update ()
{
tm += Time.deltaTime;
if (tm > waitTime) {
if(index<count-1)
{
index++;
}
else
{
index=0;
}
startChange ();
tm = 0;
}
}
void startChange ()
{
tcs [0].Reset ();
tcs [0].enabled = true;
Debug.Log ("Start");
}
void endChange ()
{
UITexture ut=GetComponent<UITexture>();
ut.material.mainTexture=Resources.Load(url+index.ToString()) as Texture;
tcs [1].Reset ();
tcs [1].enabled = true;
}
}
填写参数,完成!~
来自为知笔记(Wiz)Time=2013-04-02 14:55:52
相关文章推荐
- unity3D 涂涂乐使用shader实现上色效果
- Unity3D如何使用脚本实现跳跃的效果
- 使用ASP.NET AJAX实现幻灯片效果
- unity3d_实现幻灯片效果
- unity3d 幻灯片效果实现
- unity3d使用GUI实现打字机的文字显示效果
- 使用vs.net ajax实现幻灯片的效果
- 使用ASP.NET AJAX实现幻灯片效果
- 使用NSTimer实现倒计时,Iphone幻灯片效果+背景音乐,
- unity3d_实现幻灯片效果2
- 使用ASP.NET AJAX实现(图片)幻灯片效果
- [翻译]使用ASP.NET AJAX实现幻灯片效果
- Unity3D NGUI蒙版效果实现方法
- [翻译]使用ASP.NET AJAX实现幻灯片效果
- [翻译]使用ASP.NET AJAX实现幻灯片效果
- unity3D 涂涂乐使用shader实现上色效果
- [翻译]使用ASP.NET AJAX实现幻灯片效果
- [Unity]背包效果-使用NGUI实现物品的拖拽效果Drag
- 【转】 使用ASP.NET AJAX实现幻灯片效果
- Unity3D使用NGUI实现简单背包功能