- Home /
how to set the uv of the texture(or mesh renderer)
I wanna make a effect,just like a progress bar,at the begining,it is hidden,then you display the texture more and more,till display all of it ,how can i do that?
Answer by Peter G · Aug 09, 2013 at 03:36 AM
You shouldn't need to do any uv work. Just some clever texturing. Make a gradient bar then have an alpha cutoff based on how loaded the scene is.
See Eric's answer here for a good place to start.
http://answers.unity3d.com/questions/14770/creating-a-circular-progressbar-timer.html
about the example ,it is very thoughtful,but not fit my situation,there shader is inaccuracy and it is not flexible,thanks for the idea.
$$anonymous$$aybe I should have clarified that you can use multiple textures. With some basic texture combiners you can make pretty much any combination of textures work. And if you bring in multiple textures, you really aren't limited to just the alpha channel. You can use all 4 if you want to store data.
Answer by robertbu · Aug 09, 2013 at 08:27 AM
I'm puzzled by your 'not flexible' and 'inaccuracy' comments to @Peter G. Care to explain?
Here are two different solutions:
Attach the following script to an empty game object.
Drag and drop a texture onto the 'tex' variable.
Run the app
Adjust 'fraction' in the inspector.
pragma strict
var tex : Texture; var fraction : float = 0.5; private var screenRect = new Rect(0,0,200,50); private var sourceRect = new Rect(0,0,1,1);
function Start () { screenRect.width = tex.width; screenRect.height = tex.height; }
function OnGUI() { if(Event.current.type.Equals(EventType.Repaint)) { fraction = Mathf.Clamp01(fraction); screenRect.width = tex.width * fraction; sourceRect.width = fraction; Graphics.DrawTexture(screenRect, tex, sourceRect, 0,0,0,0); } }
For this one:
Use the CreatePlane editor script to create a plane (1x1 vertical)
Put a material with your texture on the plane
Size the plane
Attach the script below
Specify the width in world units of the plane
Run the app and adjust the 'fraction' in the inspector.
pragma strict
var fraction : float = 0.5; var width : float; // World unit width
private var position : Vector3; private var startScaleX : float; private var scale : Vector3;
function Start () { position = transform.position; scale = transform.localScale; startScaleX = scale.x; }
function Update() { fraction = Mathf.Clamp01(fraction); transform.localScale.x = startScaleX * fraction;
var posT = position; posT.x -= width * (1.0 - fraction) * 0.5; transform.position = posT; renderer.material.SetTextureScale("_MainTex", new Vector2(fraction, 1.0)); }
apologize,im not a english speaker. 'not flexible' and 'inaccuracy' means it only depends on what alpha is,that way makes you can only use the alphas-in-order texture,,it could be wrong on some texture. thanks for the advises,got more ideas on this.
Your answer
Follow this Question
Related Questions
Assigning UV Map to model at runtime 0 Answers
Rotating Textures 0 Answers
Texturing a icosphere 0 Answers
good program for uv texturing 2 Answers