Y
Y
Yura Mailler2020-08-11 08:31:46
C++ / C#
Yura Mailler, 2020-08-11 08:31:46

How to make a restriction on the movement of an object?

making a game (2D) ran into a problem that the character goes beyond the camera. I want to make it so that he could not go beyond, but I don’t know how to do it :( . here is the script (The character moves with a wave of a swipe)

float Max = 3.51f;
float Min = -3.51f;
public float position ;
public GameObject player;
  

public void OnBeginDrag(PointerEventData eventData)
{
    Vector2 delta = eventData.delta; // пк управление
   // Vector2 delta = Input.GetTouch(0).deltaPosition; --- телефон управление
    if (Mathf.Abs(delta.y) > Mathf.Abs(delta.x))
    {
        
        if (delta.x > 0) player.transform.Translate(0 , 3.50f , 0 ) ;

        else player.transform.Translate(0, -3.50f, 0 );
    }
   
}

public void OnDrag(PointerEventData eventData)
{
    
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sulim000333, 2020-08-11
@sulim000333

Colliders not an option?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question