您的位置:首页 > 编程语言

电子相册V2代码

2015-10-19 23:38 225 查看
using UnityEngine;

using System.Collections;

using UnityEngine.UI;

using UnityEngine.Events;

public class ChangePic : MonoBehaviour {

// Use this for initialization

Image img;

string[] picName = {"1","2","3","4","5","6"};

string[] buttonName = {"Uper","Down"};

string[] picImageName = {"Pic1","Pic","Pic2"};

int x = 0;

void Start () {

for (int i = 0; i<buttonName.Length; i++) {

GameObject obj = GameObject.Find (buttonName[i]);

Button but = obj.GetComponent<Button> ();

but.onClick.AddListener (

delegate() {

//this.Upper(but.name);

//this.Down(but.name);

this.UpAndDown(but.name);

});

}

for (int i = 0; i<picImageName.Length; i++) {

img = GameObject.Find (picImageName[i]).GetComponent<Image> ();

img.sprite = Resources.Load (picName [x+i], typeof(Sprite)) as Sprite;

}

}

public void UpAndDown(string str)

{

if (str == "Uper") {

x++;

if (x > picName.Length - 1) {

x = 0;

}

for (int i = 0; i<picImageName.Length; i++) {

int num = x+i;

if(num>picName.Length-1)num-=picName.Length;

img = GameObject.Find (picImageName[i]).GetComponent<Image> ();

img.sprite = Resources.Load (picName [num], typeof(Sprite)) as Sprite;

}

//img.sprite = Resources.Load (picName [x], typeof(Sprite))as Sprite;

}

if (str == "Down") {

x--;

if (x < 0) {

x = picName.Length - 1;

}

for (int i = 0; i<picImageName.Length; i++) {

int num = x+i;

if(num>picName.Length-1)num-=picName.Length;

img = GameObject.Find (picImageName[i]).GetComponent<Image> ();

img.sprite = Resources.Load (picName [num], typeof(Sprite)) as Sprite;

}

//img.sprite = Resources.Load (picName [x], typeof(Sprite))as Sprite;

}

}

// Update is called once per frame

void Update () {

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: