- Home /
Why is calling a function wrong?
I have 2 scripts. One with this function:
public void UpdateTexture (int texture)
{
foreach (Transform side in transform)
{
side.renderer.material.SetTextureScale("_MainTex", size);
side.renderer.material.SetTextureOffset("_MainTex", new Vector2(textures[texture].x*size.x, textures[texture].y*size.y));
}
}
and another script that is trying to call on that function:
currentSide.GetComponent<BlockScript>().UpdateTexture(0);
When the first script calls on the function it is correct. But when i call on that function from a different script, the texture is different and wrong. What is going on and how could i fix it? thanks
Answer by Kerihobo · Dec 13, 2014 at 07:26 AM
I am GUESSING... I havnt tested this, sue me if it doesn't work.
currentSide.GetComponent<BlockScript>().UpdateTexture(0);
could probably be:
BlockScript blockscript = YourGameObject.GetComponent<BlockScript>();
After that you can go:
blockscript.UpdateTexture(0);
Answer by Kiwasi · Dec 13, 2014 at 02:00 AM
As written this script will modify the texture of the GameObject it is on. To have it modify the calling object you must also pass I a reference to that object.
Not really, you don't have much detail in your question to go on. 'different and wrong' is not a technical term. If you explain yourself clearly we might be able to help. What exactly is happening, and what did you want to happen?
Ins$$anonymous$$d of being grass texture it is black. But when I call the function from its own script it is grass.