Added Swigs left gui text.
This commit is contained in:
parent
7c6613987e
commit
d4a6d0bb00
10 changed files with 153 additions and 128 deletions
41
Assets/Scripts/AnimateSprite.cs
Normal file
41
Assets/Scripts/AnimateSprite.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class AnimateSprite : MonoBehaviour {
|
||||
|
||||
public int columns = 2;
|
||||
public int rows = 2;
|
||||
public float framesPerSecond = 10f;
|
||||
|
||||
//the current frame to display
|
||||
private int index = 0;
|
||||
|
||||
void Start()
|
||||
{
|
||||
StartCoroutine(updateTiling());
|
||||
|
||||
//set the tile size of the texture (in UV units), based on the rows and columns
|
||||
Vector2 size = new Vector2(1f / columns, 1f / rows);
|
||||
renderer.sharedMaterial.SetTextureScale("_MainTex", size);
|
||||
}
|
||||
|
||||
private IEnumerator updateTiling()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
//move to the next index
|
||||
index++;
|
||||
if (index >= rows * columns)
|
||||
index = 0;
|
||||
|
||||
//split into x and y indexes
|
||||
Vector2 offset = new Vector2((float)index / columns - (index / columns), //x index
|
||||
(index / columns) / (float)rows); //y index
|
||||
|
||||
renderer.sharedMaterial.SetTextureOffset("_MainTex", offset);
|
||||
|
||||
yield return new WaitForSeconds(1f / framesPerSecond);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue