Hi guys!
I’m learning C#, but I’m very, very beginner at it…
I learned from unity tutorials, books about programming c#, but i decides to make something of my own.
So i have a bit struggle with my problem. I want to make a mechanic, where I can stretch or scale a ‘cube’ and than land it on another platform by dragging / swipe gesture/movement of mouse. I made this code:
public class PlayerController : MonoBehaviour {
private Vector3 swipeStart;
private Vector3 swipeEnd;
private float ratio = -0.002f;
private bool tap;
Vector3 scale;
int min_X = 1;
void Update()
{
if(Input.GetMouseButtonDown(0))
{
tap = true;
swipeStart = Input.mousePosition;
Debug.Log(Input.mousePosition);
}
else if(Input.GetMouseButtonUp(0))
{
tap = false;
swipeEnd = Input.mousePosition;
Debug.Log(Input.mousePosition);
Reset();
}
if(tap)
{
Vector3 newScale = transform.localScale * ((swipeEnd - swipeStart)* ratio).magnitude;
transform.localScale = new Vector3(transform.localScale.x, transform.localScale.y, newScale.z);
}
//if(Input.GetAxis("Mouse X") > 0)
//{
// tap = true;
//}
}
private void Reset()
{
swipeStart = swipeEnd = Vector3.zero;
}
//public Vector3 SwipeDelta { get { return swipeDelta; } }
void Start ()
{
/* if (scale.x <= 1)
{
transform.localScale = new Vector3(1.0f, transform.localScale.y, transform.localScale.z);
}
transform.localScale = new Vector3(1,1,1);
*/
}
And it works already with stretching the object in Z axis. I made also an empty gameobject, which has that script, and as a child i attached the ‘Cube’ which is the visual game Object, and we can see how it stretch. So the pivot point of the cube is the empty gameObject as a parent - and it allows to stretch/scale the cube to the 1 direction (not in both directions as a standard scaling tool).
But now i want to attach that gameobject with cube to another platform which you can see on the picture below. How to do that?