- Home /
Question by
Prd_Animator · Jan 16, 2014 at 08:26 AM ·
webplayerjavascript-specific
Problem in changing texture using javascript
I am changing signal texture color in unity as-
public class signal_change : MonoBehaviour {
int Counter=0;
int LastCounter=0;
void Start ()
{
}
void Awake()
{
//rend = gameObject.GetComponent(Renderer);
}
void Update ()
{
if (Input.GetKeyDown(KeyCode.U))
{
MyFunction("");
}
if (LastCounter != Counter) {
Counter=LastCounter;
Texture txt=null;
switch(Counter)
{
case 1:txt=Resources.Load("caution-signal", typeof(Texture2D)) as Texture;break;
case 2:txt=Resources.Load("attention-signal", typeof(Texture2D)) as Texture;break;
case 3:txt=Resources.Load("proceed-signal", typeof(Texture2D)) as Texture;break;
case 4:txt=Resources.Load("stop-signal", typeof(Texture2D)) as Texture;break;
}
renderer.material.mainTexture = txt;
}
}
public void MyFunction(string data)
{
LastCounter++;
if(LastCounter>4)
LastCounter=1;
//rend.material.mainTexture = txt;
Application.ExternalCall( "SayHello", LastCounter.ToString() );
}
}
its working fine but i want to change signal texture on the button click using javascript its not working properly.
my javascript call is-
var u = new UnityObject2();
u.getUnity().SendMessage("/MyTrafficLight/ID189", "MyFunction", "");
Comment
When using getUnity(), the u part should be the name of a GameObject and the first parameter should be the name of a script attached to the GameObject u.
Your answer
