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

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.

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);