Hi, is it possible? I found in the forum that you can reflect a texture by using Code (csharp): renderer.material.maiTextureScale.x =-1; but I would like to rotate a texture at 90 degrees. I could create separate instances of the texture outside of unity rotated at 90, 180, 270 and use that but I would like to know if I am not missing some simple way of rotating a texture inside unity. thanks
since nobody replied I would assume it's not possible. It's not a big deal anyway. I already implemented a solution that works in my case. thanks.
Yes, this can be done by creating a custom matrix. You would have to create your own shader and script for it to work though. Something like this: Javascript to place onto the GameObject: Code (csharp): var offset : Vector2; var tiling : Vector2; var rot = 45.0; function Update () { var matrix = Matrix4x4.TRS (offset, Quaternion.Euler (0, 0, rot), tiling); renderer.material.SetMatrix ("_Matrix", matrix); } And the shader: Code (csharp): Shader "Test" { Properties { _MainTex ("Base (RGB)", 2D) = "white" } SubShader { Pass { SetTexture [_MainTex] { Matrix [_Matrix] } } } }
Daniel is correct in that rotation of a texture would probably be done by a shader. The Animation API example project actually has an example of this and a shader you could probably modify to get the desired result.
Digging up an old post I know, but I am trying the same sort of thing (rotating a material) and looked up the Animation API. It's doing a similar thing to what I was trying to do in a custom shader, but unfortunately also has the same results of the material being rotated from the bottom left corner of a plane/face of cube. I need to rotate the material from the centre of the plane/cube face. Anyone know how I can do this, either a modification of above or altering a pivot point somehow?
I made a small tutorial on rotating textures: http://themaxscriptguy.wordpress.com/2014/11/20/rotating-cubemap-in-unity/https://github.com/theMaxscriptGuy/Unity_Dev/tree/master/CubeMap_Rotation
Here's a C# modification of the code above that will rotate the texture around the center: Code (csharp): public class CirclePictureAnimate : MonoBehaviour { float rotation = 0; float scale = 10; Vector3 offset = new Vector3(0.5f,0.5f,0); Vector3 tiling = new Vector3(1,1,1); Material animMat; // Use this for initialization void Start () { animMat = gameObject.renderer.materials[1]; //Debug.Log ("Material used: "+animMat.name); } void Update () { rotation += Time.deltaTime*scale; Quaternion quat = Quaternion.Euler(0,0,rotation); Matrix4x4 matrix1 = Matrix4x4.TRS (offset, Quaternion.identity, tiling); Matrix4x4 matrix2 = Matrix4x4.TRS (Vector3.zero, quat, tiling); Matrix4x4 matrix3 = Matrix4x4.TRS (-offset, Quaternion.identity, tiling); animMat.SetMatrix ("_Matrix",matrix1*matrix2*matrix3); } }
I needed to rotate a windblown sand texture. I just copied it to Pain.Net, rotated the image 90dg and then brought it back to Unity. Works like a charm.