Kernel60Hz
Decapat
- Katılım
- 22 Nisan 2023
- Mesajlar
- 227
- Çözümler
- 1
Daha fazla
- Cinsiyet
- Erkek
Kodun işlevi karakterlere basılı tutup istediğimiz yere götürebilmek Android'de test ettim çalışmıyor.
C#:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class DragAndDrop : MonoBehaviour
{
bool moveAllowed;
bool isGameOver = false;
Collider2D col;
void Start()
{
col = GetComponent<Collider2D>();
}
void Update()
{
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
Vector2 touchPosition = Camera.main.ScreenToWorldPoint(touch.position);
if (touch.phase == TouchPhase.Began)
{
Collider2D touchedCollider = Physics2D.OverlapPoint(touchPosition);
if (col == touchedCollider)
{
moveAllowed = true;
}
}
if (touch.phase == TouchPhase.Moved)
{
if (moveAllowed)
{
transform.position = new Vector2(touchPosition.x, touchPosition.y);
}
}
if (touch.phase != TouchPhase.Ended)
{
moveAllowed = false;
}
}
}
}