using UnityEngine;
using System.Collections;
public class aniSprite : MonoBehaviour {
public void aniPlay(int columnSize, int rowSize, int colFrameStart, int rowFrameStart, int totalFrames, int framesPerSecond)// function for animating sprites
{
int index = (int)(Time.time * framesPerSecond); // time control fps
index = index % totalFrames; // modulate to total number of frames
//Vector2 aa = new Vector2(1.0f, 2.0f);
Vector2 size = new Vector2((float)(1.0 / columnSize), (float)(1.0 / rowSize)); // scale for column and row size
int u = index % columnSize; // u gets current x coordinate from column size
int v = index / columnSize; // v gets current y coordinate by dividing by column size
Vector2 offset = new Vector2((float)((u + colFrameStart) * size.x), (float)((1.0 - size.y) - (v + rowFrameStart) * size.y)); // offset equals column and row
renderer.material.mainTextureOffset = offset; // texture offset for diffuse map
renderer.material.mainTextureScale = size; // texture scale for diffuse map
//renderer.material.SetTextureOffset("_BumpMap", offset); // texture offset for bump (normal map)
//renderer.material.SetTextureScale("_BumpMap", size); // texture scale for bump (normal map)
}
}
using UnityEngine;
using System.Collections;
public class playerControls : MonoBehaviour
{
private aniSprite aniSpr;
// Use this for initialization
void Start ()
{
aniSpr = GetComponent<aniSprite> ();
}
// Update is called once per frame
void Update ()
{
aniSpr.aniPlay (16, 16, 0, 1, 16, 12);
}
}
using UnityEngine;
using System.Collections;
public class playerControls0302 : MonoBehaviour {
private aniSprite aniSpr;
// Use this for initialization
void Start () {
aniSpr = GetComponent<aniSprite>();
}
// Update is called once per frame
void Update () {
if(Input.GetKey("a")) {
aniSpr.aniPlay(16, 16, 0, 1, 16, 12);
}
}
}
MonoBehavior 상속 받음
Start() / Update()
GetComponent() 함수를 통해서 컴퍼넌트들을 얻어옴
Input Class :
Inupt Manager서 세팅되어 있는 값들을 얻어 올 때 사용되는 클래스
즉, Input과 관련된 사항은 이 클래스를 사용하면 됨
GetKey() : 키가 눌려 있는 동안 True를 리턴함