- Home /
How do I pass an Texture2D from one function to another?
I'm trying to make this line work:
renderer.material.SetTexture("_MainTex", animmgr.CircusWalkRight());
animmgr.CircusWalkRight() simply returns a Texture2D - an image of Chun-Li
animmgr is a separate script which has not been tied to any object.
But for some reason, the texture is blank and white.
I get the feeling that i'm just sending a pointer or something. How do I send the texture properly?
Comment
Best Answer
Answer by dood_legacy · Jul 24, 2011 at 07:44 PM
Drag this onto a game object, and select a texture in the inspector for swapTexture. When you start up the game, just click the mouse and you will see the texture swap.
public var swapTexture : Texture2D;
function Update ()
{
if ( Input.GetMouseButtonDown(0) )
{
renderer.material.SetTexture("_MainTex", Swap());
}
}
function Swap() : Texture2D
{
return swapTexture;
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612154102im_/https://answers.unity.com/themes/thub/images/avi.jpg)