- Home /
Variable direction scrolling textures.
What i'm trying to do is to make a scrolling texture that scrolls to the direction an empty is rotated.
I've looked trough the scrolling texture script and i think i understand how it works, But i have no idea where to start with this. Is there any easy way to get the rotation value of certain axis and transfer it to the direction a texture is scrolling?
I ment a script that reads the angle of the empty game object and updates the direction of the scrolling texture. The empty has no scripts attached to it, yet.
Answer by robertbu · Aug 13, 2013 at 02:41 PM
Solving this by reading an angle is not advised. 'eulerAngles' can change representation and therefore would only work through some restricted ranges of rotation. But you can use a vector such as transform.up or transform.right. The following code uses the x and y components of transfor.right. Rotate 'directionObject' around the 'z' axis to point the direction of the scroll. If you are going to allow arbitrary rotation of the 'directionObject', then you want to zero out the 'z' component and normalize the result before applying it.
#pragma strict
var directionObject : Transform;
var speed = 0.2;
private var offset = Vector2(1,1);
function Update () {
offset -= speed * Time.deltaTime * directionObject.right;
renderer.material.SetTextureOffset("_MainTex", offset);
}
Your answer
Follow this Question
Related Questions
Get Asset Preview (3.5) 1 Answer
Object dark even in light 2 Answers
C4D texture projection 1 Answer
Texture blending 0 Answers
Unity ignores textures inside transparent objects. Need help! 2 Answers