Search Unity

Question about Material.mainTextureOffset

Discussion in 'Scripting' started by flyric123, May 23, 2011.

  1. flyric123

    flyric123

    Joined:
    May 8, 2011
    Posts:
    13
    Hi, there,
    I am wondering whether we can use Material.mainTextureOffset to change the texture outside the function Update()?
    I mean I want to import image as texture at runtime and adjust the offset of the texture image. But when using the Material.mainTextureOffset function in the OnGUI(), I found the offset of the texture is always reset. Is there a way to do what I want with Material.mainTextureOffset?

    Here is the code:
    image_position = render.material.GetTextureOffset('_MainTex')
    if GUI.Button(Rect(GetPositionX(3) - 10,GetPositionY(3),42,42),"Up"):
    image_position.y -= 0.1
    render.Material.mainTextureOffset = Vector2(image_position.x, image_position.y)
    #I also use render.sharedMaterial.mainTextureOffset = Vector2(image_position.x, image_position.y) here,
    #but it does not work well either.

    And I also try the function Material.TextureOffset, it does not work either.

    Thanks in advance!