Messing with patron objects.
This commit is contained in:
parent
f82c126b8a
commit
abf4983ffa
12 changed files with 448 additions and 159 deletions
|
|
@ -31,11 +31,10 @@ public class AnimateSprite : MonoBehaviour {
|
|||
//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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 704d6d277dc28fa4c8a6a28688efd5a3
|
||||
guid: 019afbbcd27acf941b76ed7fd6a4eeb2
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
|
|
|
|||
41
Assets/Scripts/AnimateTexture.cs
Normal file
41
Assets/Scripts/AnimateTexture.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class AnimateTexture : 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
8
Assets/Scripts/AnimateTexture.cs.meta
Normal file
8
Assets/Scripts/AnimateTexture.cs.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 704d6d277dc28fa4c8a6a28688efd5a3
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
Loading…
Add table
Add a link
Reference in a new issue