tanyakoding
0

Fungsi dari coding ini untuk apa yaa?

19/1/202350 viewsoleh: Nur Hadi Hidayat

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Puzzle1 : MonoBehaviour { public Transform Puzzle_1; private Vector2 initialPos; private Vector2 touchPos; private float deltaX, deltaY; private Touch touch;

public static bool locked;




// Start is called before the first frame update
void Start()
{
    initialPos = transform.position;
    locked = false;

}

// Update is called once per frame
void Update()
{
    if (Input.touchCount > 0 && !locked)
    {
        touch = Input.GetTouch(0);
        touchPos = Camera.main.ScreenToWorldPoint(touch.position);

        if (touch.phase == TouchPhase.Began)
        {
            if (GetComponent<Collider2D>() == Physics2D.OverlapPoint(touchPos))
            {
                deltaX = touchPos.x - transform.position.x;
                deltaY = touchPos.y - transform.position.y;

                return;
            }
        }
        if (touch.phase == TouchPhase.Moved)
        {
            if (GetComponent<Collider2D>() == Physics2D.OverlapPoint(touchPos))
            {

                transform.position = new Vector2(touchPos.x - deltaX, touchPos.y - deltaY);
            }
        }
        if (touch.phase == TouchPhase.Ended)
        {
            if (Mathf.Abs(transform.position.x - Puzzle_1.position.x) <= 0.5f &&
                Mathf.Abs(transform.position.y - Puzzle_1.position.y) <= 0.5f)
            {
                transform.position = new Vector2(Puzzle_1.position.x, Puzzle_1.position.y);
                locked = true;
            }
            else
            {
                transform.position = new Vector2(initialPos.x, initialPos.y);
            }

        }
    }


}///update class

}//class



0 Jawaban

Login dulu untuk memberikan jawaban.

login google
© 2023 tanyakoding.com · about · privacy