2D Sprite animation JS to C#

[Tutorial 2D asset step 5][1]

This is the tutorial I am following. Now in this part we are letting the 2d sprite move by the code and if done correctly you will see an animated character. Lovely.

When I plant the code the tutorial guy is providing me with on the square with the mushroom (so im planting the javascript on it) it works like he is showing.

However if I use the C# on the square mushroom it doesn’t work and it will just slide the entire texture from left to right or vice versa.

help?!?!


Javascript foto. Animation in place

!

[2]

<hr>

C# foto. Not animation in place.

![C#][3]

<hr>

Javascript

    var column : int;
    	var row : int;
    	var framesPerSecond = 8.0;
    	
    	function Update ()
    	{
    		var index : int = Time.time * framesPerSecond;						
    		index = index % (column * row);									
    		
    		var size = Vector2 (1.0 / column, 1.0 / row);			
    		var offset = Vector2 (index * size.x, row);			
    		
    		renderer.material.mainTextureOffset = offset;					
    		renderer.material.mainTextureScale = size;						
    	}

<hr>
C#

    using UnityEngine;
    using System.Collections;
    
    public class Step5 : MonoBehaviour
    {
    	public int column = 16;
    	public int row = 1;
    	public int framesPerSecond = 8;
    	
    	void Update ()
    	{
    		float index = Time.fixedTime * framesPerSecond;						//time control fps
    		index = index % (column * row);									//modulate
    		
    		Vector2 size = new Vector2 (1.0F / column, 1.0F / row);			//scale
    		Vector2 offset = new Vector2 (index * size.x, row);				//offset
    		
    		renderer.material.mainTextureOffset = offset;					//texture offset
    		renderer.material.mainTextureScale = size;						//texture scale
    	}
    }
    
I'm not getting any errors as the code works, just not the way it should happen. I tried changing the time to deltaTime, i tried changing values. Yet again, I am stuck.

  [1]: http://vimeo.com/couchmode/album/1546437/sort:preset/20693444
  [2]: /storage/temp/19582-java.png
  [3]: /storage/temp/19583-c#.png

here is two different ways to run animation

this is for image sequence

public Texture2D[] frames;
public float framesPerSecond = 10.0f;

void Update () {
    float index = Time.time * framesPerSecond;
    index = index % frames.Length;

    renderer.material.mainTexture = frames[index];
}

Here is second method to run animation sheet

	public float uvAnimationTileX = 6; 
	public float uvAnimationTileY = 1;
	
	float framesPerSecond = 10.0f;
	 
	void Update () {
	 
		// Calculate index
		float index = Time.time * framesPerSecond;
		// repeat when exhausting all frames
		index = index % (uvAnimationTileX * uvAnimationTileY);
	 
		// Size of every tile
		var size = Vector2 (1.0f / uvAnimationTileX, 1.0f / uvAnimationTileY);
	 
		// split into horizontal and vertical index
		var uIndex = index % uvAnimationTileX;
		var vIndex = index / uvAnimationTileX;
	 
		// build offset
		// v coordinate is the bottom of the image in opengl so we need to invert.
		var offset = Vector2 (uIndex * size.x, 1.0f - size.y - vIndex * size.y);
	 
		renderer.material.SetTextureOffset ("_MainTex", offset);
		renderer.material.SetTextureScale ("_MainTex", size);
}

Hope this is helpful for you…

This is the Perfect working codeenter code here
using UnityEngine;
using System.Collections;

public class AnimationSS : MonoBehaviour {

// Use this for initialization

public float uvAnimationTileX = 6; 
public float uvAnimationTileY = 1;

float framesPerSecond = 10.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);
}

}