Bonfire184
Bonfire184

Reputation: 127

Slide my menu screen straight up to enter game in Unity

I have an intro type splash screen that I want the user to touch at the bottom, then proceed to slide upwards with his finger. I want the splash screen to move only up on the y-axis and move out of the screen eventually disappearing when the bottom edge of the image reaches the top of the user's screen.

The only thing I can find that emulates this is the windows 10 intro before logging in where the image moves up and off the screen to show the log in box underneath.

I'm not looking for someone to do the work for me, but I can't wrap my mind around how to begin the code or finger input. Do you have any ideas? Thanks!

Upvotes: 1

Views: 128

Answers (1)

pasotee
pasotee

Reputation: 348

You really got 2 options. You can use the EventHandlers with IDragHandler, IBeginDragHandlerand and IEndDragHandler and calculate the distance between the initial position (start of drag) and final position (release of the drag)

public class DragDrop : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler {


private Vector3 startPosition;
private Vector3 endPosition;

private float distanceToDrag;

public void OnBeginDrag(PointerEventData eventData)
{
    startPosition = Input.GetTouch(0).position; // get current Tocuh position
}

public void OnDrag(PointerEventData eventData)
{
    //Drag your UI as you wish
}

public void OnEndDrag(PointerEventData eventData)
{
    endPosition = Input.GetTouch(0).position; // get current Tocuh position
    float distance = Vector2.distance(startPosition,endPosition);

    if (distance > distanceToDrag)
        //start the game
    else
        //Put the UI back.
}
}

Or you can use the event system.

Upvotes: 1

Related Questions