play texture animation

hey,
i want to play animation when i click the object like leaver which power on the machine.
similar i did here when i click the leaver it plays the animation of leaver and after that machine it works fine.

my prob is i also have texture that i want to animate when i click on leaver
i have script which can animate texture but it works on object not on fbx.

i tried this script. tell me where am i doing wrong ??

var wasClicked: boolean = false;

var scrollSpeed : float = 0.5;





function OnMouseUp() {

    wasClicked = true; // turns on button.

	}

var target : GameObject;

var target_2 : GameObject;

var fabric_1 : GameObject;

var fabric_2 : GameObject;





function OnMouseDown(){

    Debug.Log("Object clicked");

 target = GameObject.Find("Leaver");

 target.animation.Play();

 

yield WaitForSeconds (1);



 target_2 = GameObject.Find("machine_5");

 target_2.animation.Play();

 

 fabric_1 = GameObject.Find("Object001");

 var offset : float = Time.time * scrollSpeed;

    fabric_1.renderer.material.mainTextureOffset = Vector2 (offset, 0);

 

 fabric_2 = GameObject.Find("Object004");

 offset = Time.time * scrollSpeed;

    fabric_2.renderer.material.mainTextureOffset = Vector2 (offset, 0);

      

    }

regards

thanx

I’ve only started on creating meshes and playing with them, but was curious about reading the mesh of an imported model, so I have been experimenting.

I created a cube, then an icosohedron in Blender, both with the same ‘Cliff’ texture, then exported them as .fbx

then attached the following script to each of them. And with both on stage it was only 1 drawcall (with different scrollspeeds even). if you map the uv’s correctly in your modelling program I’m sure you can control the direction of offset for each tri. Also make sure the texture wrap mode is set to ‘repeat’. See how it works for you =]

#pragma strict

public var scrollSpeed : float = 0.1;

function Update() 
{
	SwapUVs();
}

function SwapUVs()
{
	var mesh : Mesh = this.transform.GetComponent(MeshFilter).mesh;
	var uvSwap : Vector2[] = mesh.uv;
	
	for (var b:int = 0; b < uvSwap.length; b ++)
	{
		uvSwap __+= Vector2( scrollSpeed * Time.deltaTime, 0 );__

** }**

** mesh.uv = uvSwap;**
** }**
EDIT : to add this to your current script, try this re-write (untested):
** var wasClicked: boolean = false;**
** var scrollSpeed : float = 0.5;**
** function OnMouseUp() {**
** wasClicked = true; // turns on button.**
** }**
** var target : GameObject;**
** var target_2 : GameObject;**
** var fabric_1 : GameObject;**
** var fabric_2 : GameObject;**
** var isScrollingUV : boolean = false;**
** function OnMouseDown() {**
** // Debug.Log(“Object clicked”);**

** target = GameObject.Find(“Leaver”);**
** target.animation.Play();**

** yield WaitForSeconds (1);**

** target_2 = GameObject.Find(“machine_5”);**
** target_2.animation.Play();**

** fabric_1 = GameObject.Find(“Object001”);**
** fabric_2 = GameObject.Find(“Object004”);**

** isScrollingUV = true;**
** }**
** function Update() {**
** if (isScrollingUV) {**
** SwapUVs();**
** }**
** }**
** function SwapUVs() {**
** var mesh1 : Mesh = fabric_1.transform.GetComponent(MeshFilter).mesh;**
** var uvSwap1 : Vector2 = mesh1.uv;**

** var mesh2 : Mesh = fabric_2.transform.GetComponent(MeshFilter).mesh;**
** var uvSwap2 : Vector2 = mesh2.uv;**
** for (var b:int = 0; b < uvSwap1.length; b ++) {**
uvSwap1 += Vector2( scrollSpeed * Time.deltaTime, 0 );
** }**
** for (b = 0; b < uvSwap2.length; b ++) {**
uvSwap2 += Vector2( scrollSpeed * Time.deltaTime, 0 );
** }**
** mesh1.uv = uvSwap;**
** mesh2.uv = uvSwap;**
** }**