- Home /
Cutting sprite instead of stretching
Hi, I'm using a Raycast system™ to determine the size of my sprite laser. To increase / decrease the sprite I use transform.scale.x
. The problem is that I need to cut the sprite to the desired size and not stretch it. How do I do this? Example stretching sprite:
Thanks in advance.
Answer by robertbu · Aug 05, 2014 at 03:10 PM
Change from using a Sprite to display the laser beam and use a Quad instead. Then you can adjust the tiling/scale in material:
http://docs.unity3d.com/ScriptReference/Material-mainTextureScale.html
You'll have to map your transform.localScale.x changes to the mainTextureScale changes.
renderer.material.mainTextureScale = Vector2(transform.localScale.x, 1.0);
Note you can take this a bit further. If you create just one section of the beam and make that section tile, then you can create a whole beam out of just a small section.
Your answer
Follow this Question
Related Questions
How to position Sprite sliced/cut parts? 0 Answers
Occlusion Culling for 2D sprite (SpriteRenderer) 0 Answers
Unity 2D blending sprites 0 Answers
How to create outline circle sprite? 1 Answer
Unity 2D: Design a custom slider object with custom sprites 0 Answers