- Home /
How to stretch my scale in unity 3d ?
Hi All,
I think i had face some tricky situation in the unity 3d.
Actually my task is to stretch my scale to some point.
below is my scale look in the scene. if i drag a point to upwards i want my scale is stretch to upwards in the same scale.
the scale part is a maya game object with texturing.
For suppose if i drag a point to 3.4 in the y direction. than i want to show my scale is 4 times.with same texturing in y direction. in the same way x direction also.
please tell me a way how to do that task. i am little new to this type of tasks.
can i get a reference or else any coding help.
please help me
Thanks & Regards
Shankar
Answer by robertbu · May 07, 2013 at 03:52 PM
One approach is to increase the tiling of the texture as the height of the object is increased:
function Update () {
renderer.material.mainTextureScale = Vector2(1.0, transform.localScale.y);
}
I ran a quick test with a plane and a cylinder using your ruler above, and it worked. But if you've UV mapped the texture onto the 3D object it will not work.
Thanks for answering $$anonymous$$r. Robertube,
really i didn't get your answer. I tired ur code but that not shown even my texture also.
In a scene i have this object and main camera.
I want to write code, if i drag my mouse to upwards in a 4.5 points distance i want to show that object with 5 points height with proper texturing.
ruler is a object the place of the object is fixed. if i drag downwards i want to calculate the distance depended up on the distance i want to increase the length of the scale.
please help me.
Thanks you
shankar
Your question as indicated in your followup information involves multiple technical questions 1)capturing mouse input 2) calculating vector3 positions in world coordinates based on mouse positions, 3) sizing and rotating object to fit between two Vector3s, etc. All of these have been answered multiple times on this list, and I'm not going to write the code for you. I suggest you tackle each one in turn, and if you get stuck, open a new question. The one piece of your problem I have not seen (and it may be there) was tiling the texture based on the height of the object. I wasn't sure how well it would work, but the results were surprising good. To reproduce my results, do the following:
Put the CreatePlane script in your Assets/Editor folder.
Create a vertical plane using the script. GameObject/Create Other/Custome Plane...
Set the X scale of the plane to .5 (just for looks).
Create a new material with an Unlit/Texture shader. Use the ruler in a vertical orientation as the texture. Apply the texture to the plane.
Put my code fragment above into a script and attach it to the plane.
Run the app. While running, select the plane in the hierarchy and adjust the Y scale.
This also worked with a cylinder (though obviously the ends of the cylinder get the texture as well which is problematic).
Here is the texture I used (clipped from your post):