using System.Collections;

using System.Collections.Generic;

using UnityEngine;


public class Drag : MonoBehaviour

{

ย  ย  float deltax;

ย  ย  float deltay;

ย  ย  private Rigidbody2D rb;

ย  ย  //-----------------------------------------------------------------------------

ย  ย  public Vector3 moveVelocity;

ย  ย  public float movePower = 0.5f;

ย  ย  float moveVelocityx = 1;

ย  ย  float moveVelocityy = 1;

ย  ย  //----------------------------------------------------------------------------


ย  ย  private void Start()

ย  ย  {

ย  ย  ย  ย  rb = GetComponent();

ย  ย  }


ย  ย  private void Update()

ย  ย  {

ย  ย  ย  ย  StartCoroutine(StopGroundPopUp());

ย  ย  ย  ย  StartCoroutine(Drag1());

ย  ย  }


ย  ย  void Movedd()// ํ”Œ๋ ˆ์ด์–ด๊ฐ€ ์™ผ์ชฝ์œผ๋กœ ์ด๋™ํ•˜๋Š” ํ•จ์ˆ˜.ย 

ย  ย  {

ย  ย  ย  ย  moveVelocity = new Vector3(moveVelocityx, moveVelocityy, 0);

ย  ย  ย  ย  transform.position += moveVelocity.normalized * movePower * Time.deltaTime;

ย  ย  }

ย  ย  IEnumerator StopGroundPopUp()

ย  ย  {

ย  ย  ย  ย  Movedd();

ย  ย  ย  ย  yield return new WaitForSeconds(0.5f);

ย  ย  }


ย  ย  IEnumerator Drag1()

ย  ย  {

ย  ย  ย  ย  if (Input.touchCount > 0)// initiating touch event, if touch event takes place

ย  ย  ย  ย  {

ย  ย  ย  ย  ย  ย  Touch touch = Input.GetTouch(0); // get touch to take a deal withย 

ย  ย  ย  ย  ย  ย  Vector2 touchpos = Camera.main.ScreenToWorldPoint(touch.position);ย 


ย  ย  ย  ย  ย  ย  switch (touch.phase)

ย  ย  ย  ย  ย  ย  {

ย  ย  ย  ย  ย  ย  ย  ย  case TouchPhase.Began:

ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  deltax = touchpos.x - transform.position.x;

ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  deltay = touchpos.y - transform.position.y;

ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  break;


ย  ย  ย  ย  ย  ย  ย  ย  case TouchPhase.Moved:

ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  rb.MovePosition(new Vector2(touchpos.x - deltax, touchpos.y - deltay));

ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  break;


ย  ย  ย  ย  ย  ย  ย  ย  case TouchPhase.Ended:

ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  rb.velocity = Vector2.zero;

ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  break;

ย  ย  ย  ย  ย  ย  }


ย  ย  ย  ย  }


ย  ย  ย  ย  yield return new WaitForSeconds(0.5f);

ย  ย  }

}









์บ๋ฆญํ„ฐ๊ฐ€ ์›€์ง์ด๋Š” ์ƒํƒœ์—์„œ ์˜†์œผ๋กœ ๋“œ๋ž˜๊ทธํ•˜๋ฉด ๋“œ๋ž˜๊ทธํ•œ ๋ฐฉํ–ฅ์œผ๋กœ ์ด๋™ํ•˜๋Š”๊ฑธ ๋งŒ๋“ค๊ณ  ์žˆ๋Š”๋ฐ

๋“œ๋ž˜๊ทธํ•œ ๋ฐฉํ–ฅ์œผ๋กœ ๋ฐฉํ–ฅ์„ ๋Œ๋ฆฐ๊ฑด ๋‘˜์งธ ์น˜๋”๋ผ๋„ ์›€์ง์ด๋Š”์ƒํƒœ์—์„œ๋Š” ๋“œ๋ž˜๊ทธ๊ฐ€ ์•ˆ๋˜๋„ค. ๋ฌด์—‡์„ ๋ฐ”๊ฟ”์•ผ ๋ ๊นŒ?

์ฝ”๋ฃจํ‹ด์œผ๋กœ ๋Œ๋ฆฌ๋ฉด ํ•ด๊ฒฐ๋ ๊นŒ ์‹ถ์–ด์„œ ๋‘˜๋‹ค ์ฝ”๋ฃจํ‹ด์œผ๋กœ ๋Œ๋ ธ๋Š”๋ฐ๋„ ์›€์ง์ด๋Š” ๋„์ค‘์— ๋“œ๋ž˜๊ทธ๊ฐ€ ์•ˆ๋จ