C# コルーチンをコールする Unity
IEnumerator Hoge() { // do something }
Hoge();
↑これだとコールされないっぽい。
StartCoroutine(Hoge());
↑または。。。
StartCoroutine("Hoge");
↑こうやってコールしなきゃだめ
タイルマップをJSのC#化 Unity
最近C#化してるので移植したhttp://www.unifycommunity.com/wiki/index.php?title=Animating_Tiled_texture_-_Extended
- AnimatedTextureExtendedUV.cs
using UnityEngine; using System.Collections; public class AnimatedTextureExtendedUV : MonoBehaviour { //vars for the whole sheet public int colCount = 4; public int rowCount = 4; //vars for animation public int rowNumber = 0; //Zero Indexed public int colNumber = 0; //Zero Indexed public int totalCells = 4; public int fps = 10; Vector2 offset; //Maybe this should be a private var //Update void Update () { transform.eulerAngles = new Vector3(90, 180, 0); SetSpriteAnimation(colCount,rowCount,rowNumber,colNumber,totalCells,fps); } //SetSpriteAnimation void SetSpriteAnimation (int colCount, int rowCount, int rowNumber, int colNumber, int totalCells, int fps) { // Calculate index float index = Time.time * fps; // Repeat when exhausting all cells index = index % totalCells; // Size of every cell Vector2 size = new Vector2(1.0F / colCount, 1.0F / rowCount); // split into horizontal and vertical index int uIndex= (int)index % colCount; int vIndex= (int)index / colCount; // build offset // v coordinate is the bottom of the image in opengl so we need to invert. offset = new Vector2((uIndex+colNumber) * size.x, (1.0F - size.y) - (vIndex+rowNumber) * size.y); renderer.material.SetTextureOffset ("_MainTex", offset); renderer.material.SetTextureScale ("_MainTex", size); } }