Hi All
I have downloaded the java script from the unity forum for animating sprites
#pragma strict
var uvX = 4;
var uvY = 2;
var fps = 24.0;
function Update () {
var index : int = Time.time * fps;
index = index % (uvX * uvY);
var size = Vector2 (1.0 / uvX, 1.0 / uvY);
var uIndex = index % uvX;
var vIndex = index / uvX;
var offset = Vector2 (uIndex * size.x, 1.0 - size.y - vIndex * size.y);
GetComponent.<Renderer>().material.SetTextureOffset ("_MainTex", offset);
GetComponent.<Renderer>().material.SetTextureScale ("_MainTex", size);
}
but when i converted into C#
using UnityEngine;
using System.Collections;
public class AnimationSS : MonoBehaviour {
// Use this for initialization
public float uvAnimationTileX = 4;
public float uvAnimationTileY = 2;
public float framesPerSecond = 24.0f;
void Update () {
// Calculate index
float index = Time.time * framesPerSecond;
// repeat when exhausting all frames
index = index % (uvAnimationTileX * uvAnimationTileY);
// Size of every tile
Vector2 size =new Vector2 (1.0f / uvAnimationTileX, 1.0f / uvAnimationTileY);
// split into horizontal and vertical index
float uIndex = index % uvAnimationTileX;
float vIndex = index / uvAnimationTileX;
// build offset
// v coordinate is the bottom of the image in opengl so we need to invert.
Vector2 offset = new Vector2 (uIndex * size.x, 1.0f - size.y - vIndex * size.y);
GetComponent<Renderer>().material.SetTextureOffset ("_MainTex", offset);
GetComponent<Renderer>().material.SetTextureScale ("_MainTex", size);
}
}
The C# coding is working. But the output is highly difference in js coding. I dont know what i am making mistake… I want the same output as the js file. Could any one help me… What i have done wrong in C# file…
Thanks in Advance