Problem with a simple script!?

Hello I been following walker boys tutorials on how to make a 2D game in unity everything has been working well until i reached this script which is supposed to offset and scale the sheet so its looks like its animating I found the problem but I cant find the solution.The problem is that the material is getting Y offset set to 1 so the images disappears I need to set it to 0 but as 0 cant be divided I’m getting errors in console.In the video his offset is set to 1 but in my case if I set to 1 images disappears.I checked the script a lot of times and modified it but nothing helped and the script is the same as theirs.

var column : int; //U
var row : int; //V
var index : int = 1;

function Update ()
{
	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;
}

your not using Time anywhere in that code to shuffle the offset. In every case ever that i have used offset textures during runtime , the value is calculated based on some form of time.

Here is the video:http://vimeo.com/album/1546437/video/20693356
I never seen them using time and they script works perfectly well in that video even if its the same as mine.

lol - well i trust ye , but im not watching the video , im just saying i use scrolling textures all the time , and i drive them with time.

Its mostly the case of , that im looking at your code , and it seems that no matter what , Offset will ALWAYS have the exact same value … you need to increment or decrement it over time. Be it with time , or an incermental counter , whatever have you. Anyways you slice it though , its time thats going to allow you to move it. Naturally it moves over time , or it doesnt move at all.

I dont need time in that script,if i used time it would just play until the game ends.They need to be played when i call them thats something i know how to do.

I am not saying you need time directly , but i am saying that without some form of timing , your not moving it. As long as your offeset value keeps coming back as exactly the same value , no move , no notta. Seems very logical to me.

And just beacuse you use time does not mean things happen until end of game. Use control scripts to make it do what you want.

PS : adda debug.log statement , and see if your offset values are constantly the same value. I suspect this is indeed the problem.

PS PS : , one last thing i just noticed , your variabls are all int’s , but uv offset takes a floating point value, 0.000000 - 1.0000, could be an issue for you as well.

When I drag the index it increases the index number all the way to 15 so it changes the offset and tile number.

irealise that , but an offset is a value between 0 - 1… if you just have it seting to whole nmbers over and over , its not gonna appear to do anything. Anyways , im running out of ways to explain it to you , good luck!

I understand but why is their script working which is the same as mine but mine isnt?

I dont know , i ahvent watched their video , or read any tutorial of the such , im just telling you my experiences and how easy it is to do. As long as you have a floating point increment , or decrement , because really , an offset value , if it goes past 1 is just repeating the exact values that 0-1 provides.

In other words , if you offset it 0.9 , or 3.9 , its the same thing. anyhting above 1 is truly irrelevant. If all your using is whole numbers , than it is never truly offsetting anything.

It might worth to post a screen with your setup.
What is the value of the offset when you change the index?
If you drag the mouse like he does, the value of the offset should increase from zero to one, since his animation method is doing just that, offsets the texture over the time to create the illusion of an animated sprite.

You will add time component in some later video, now try to adjust the tiling, I checked at my lab and it is set to 0.0625 for both x and y.

I was looking things over, as well. You’ll probably want to double check your settings, but also be sure to continue through to part 3_10. That will provide you the full functionality of the sprite animation system. If things are still not working properly, just let me know. Thank you.

OK,thanks!

Fixed the problem!The problem was not in the script i think that it was in the camera(out of field of view) or in unity because after i restarted everything worked OK.

Now i have another problem after i finished the system i have a problem that script will only play 4 out of 8 columns.The problem only occurs on a sheet which has 2 rows.It looks like the offset will go only up to 0.875 and then reset to 0 i tried different numbers none worked .On a sheet with 1 row offset will go up to 0.9375 and then back to 0 and it works if it goes like that.

function aniSprite (columnSize,rowSize,colFrameStart,rowFrameStart,totalFrames,framesPerSecond)
{
	var index :int = Time.time * framesPerSecond;
	index = index % totalFrames;
	
	var size = Vector2 ( 1.0 / columnSize, 1.0 / rowSize);
	
	var u : int = index % columnSize;
	var v : int = index / columnSize;
	
	var offset = Vector2 ((u + colFrameStart) * size.x,(1-size.y) - (v + rowFrameStart * size.y));
	
	renderer.material.mainTextureOffset = offset;
	renderer.material.mainTextureScale = size;
}
function Update ()
{
	var aniPlay = GetComponent(aniSprite);
	if(Input.GetKey("a"))
	{
		aniPlay.aniSprite (8,2,0,0,16,12);
	}

}

Anyone?

I noticed that when it playes the animation that half of the animation is played on 1 row and half of the animation on the 2 row.

Hi, what solution for jump in mario 3D clone???