using System.Collections;
using UnityEngine.Android;
using UnityEngine;
using System.Diagnostics;
public class ScaleChanger : MonoBehaviour
{
private Rigidbody rb;
private float deltaY;
public float sens;
private Vector3 scale;
private float distance;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
Vector3 touchPos = (touch.position * Time.fixedDeltaTime);
scale = new Vector3(transform.localScale.x, transform.localScale.y, 2);
switch (touch.phase)
{
case TouchPhase.Began:
//deltaY is the starting point of your finger
deltaY = touchPos.y;
break;
case TouchPhase.Moved:
//finger down
if (deltaY - 3 > touchPos.y)
{
scale = new Vector3(Mathf.Clamp(transform.localScale.x + (deltaY + 3 - touchPos.y) / sens, 1, 5), Mathf.Clamp(transform.localScale.y - (deltaY + 3 - touchPos.y) / sens, 1, 5), 2);
}
//finger up
else if (deltaY + 3 <= touchPos.y)
{
scale = new Vector3(Mathf.Clamp(transform.localScale.x - ((deltaY + 3 - touchPos.y) * -1) / sens * 3, 1, 5), Mathf.Clamp(transform.localScale.y + ((deltaY + 3 - touchPos.y) * -1) / sens * 3, 1, 5), 2);
UnityEngine.Debug.Log("ok 3");
}
//finger down
else if (deltaY - 2 > touchPos.y)
{
scale = new Vector3(Mathf.Clamp(transform.localScale.x + (deltaY + 2 - touchPos.y) / (sens * 5), 1, 5), Mathf.Clamp(transform.localScale.y - (deltaY + 2 - touchPos.y) / (sens * 5), 1, 5), 2);
}
//finger up little
else if (deltaY + 2 <= touchPos.y)
{
scale = new Vector3(Mathf.Clamp(transform.localScale.x - ((deltaY + 2 - touchPos.y) * -1) / (sens * 5), 1, 5), Mathf.Clamp(transform.localScale.y + ((deltaY + 2 - touchPos.y) * -1) / (sens * 5), 1, 5), 2);
UnityEngine.Debug.Log("ok 2");
}
//finger down very little
else if (deltaY - 1.5 > touchPos.y)
{
scale = new Vector3(Mathf.Clamp(transform.localScale.x + (deltaY + 1.5f - touchPos.y) / (sens * 10), 1, 5), Mathf.Clamp(transform.localScale.y - (deltaY + 1.5f - touchPos.y) / (sens * 10), 1, 5), 2);
}
//finger up very little
else if (deltaY + 1.5 <= touchPos.y)
{
scale = new Vector3(Mathf.Clamp(transform.localScale.x - ((deltaY + 1.5f - touchPos.y) * -1) / (sens * 10), 1, 5), Mathf.Clamp(transform.localScale.y + ((deltaY + 1.5f - touchPos.y) * -1) / (sens * 10), 1, 5), 2);
UnityEngine.Debug.Log("ok 1");
}
/* deltaY live movement try (not working properly)*/
//finger up deltaY renew
if (deltaY < touchPos.y - 5)
{
deltaY = touchPos.y - 3;
}
//finger down deltaY renew
if (deltaY > touchPos.y + 5)
{
deltaY = touchPos.y + 4;
}
transform.localScale = scale;
break;
}
}
}
}