What is the best way to go about this?
What I’m trying to do, is to stretch the object along the X axis while the finger is touching the screen and when the finger is lifted the object falls down. The problem is that my script works fine when a solid color is applied (red, white, black, etc. ), but when I try to import some custom sprites, for example planks, the sprite quality distorts, because of stretching. Is there a way to maintain the same quality when the sprite is stretched ? I think the way to go about this is to use solid color while it is stretching and after the finger is released apply the sprite, but I have no idea how to achieve this.
Script:
public class Extend : MonoBehaviour
{
public float speed = 0.2f;
Rigidbody2D rb;
public GameObject line;
bool TouchInputOff = false;
private void Awake()
{
rb = GetComponent<Rigidbody2D>();
}
private void Update()
{
if (!TouchInputOff)
{
if (Input.GetMouseButton(0))
{
line.transform.localScale = new Vector3(transform.localScale.x + 0.2f * speed, transform.localScale.y, 0);
}
if (Input.GetMouseButtonUp(0) || line.transform.localScale.x >= 5.0f)
{
rb.gravityScale = 3;
TouchInputOff = true;
}
}
else
{
rb.gravityScale = 3;
}
}
}