【发布时间】:2014-09-18 22:19:53
【问题描述】:
我正在尝试仅使用一个精灵在我的场景中生成多个精灵。当我尝试使用精灵数组和精灵渲染器时,我发现它很困难,因为在我的场景中我只看到一个精灵。我还想在 Unity 场景的不同区域显示精灵。
主要代码:
using UnityEngine;
using System.Collections;
public class SampleCode : MonoBehaviour {
float posX = -4.5F;
float posY = -0.65F;
public IEnumerator Start(){
for(int i = 0; i < 5; i++){
posX = posX + 0.65F;
if(posX > 3.5F){
for(float x = 0.50F; x < 2.5F; x = x + 0.50F){
posY = -1.5F + x;
posX = -4.15F + x;;
}
}
string path = "file:///C:/Users/Pankaj Sharma/Documents/untitled.bmp";
SpriteRenderer rend = this.GetComponent<SpriteRenderer>();
Sprite sprite = new Sprite();
WWW www = new WWW(path);
yield return www;
sprite = Sprite.Create(www.texture, new Rect(0, 0, 50, 50),new Vector2(posX, posY),100.0f);
rend.sprite = sprite;
}
}
}
【问题讨论】: