تاچ استیک_کشیدن و رها کردن یک عکس در یونیتی/ touch stick در یونیتی (برای دکمه ی مجازی کنترلی بازی اندروید)
شنبه, ۴ مهر ۱۳۹۴، ۱۱:۲۸ ب.ظ
منبع:gameover.blog.ir
یک ui->Canvas ایجاد کنید.
یک ui->Canvas ایجاد کنید.
سپس دو image در زیر شاخه ی Canvas ایجاد کنید.یکی عکس دایره تو خالی بزرگ و یکی برای دایره ی توپر کوچک داخلی که قراره با ماوس بگیریم و بکشیم و رها کنیم.
می تونید این دو عکس رو دانلود کنید :
http://s6.picofile.com/file/8214240134/1.png
http://s3.picofile.com/file/8214240176/2.png
نکته:
خصوصیت شناور بودن image ها رو روی پایین و چپ بگذارید.
کد سیشارپ زیر رو بندازید روی image یا دایره ی توپر داخلی:
//keshidan va raha kardan //csharp code //Unity 5 //Author:gameover.blog.ir using UnityEngine.EventSystems; using UnityEngine; using System.Collections; public class touch1 : MonoBehaviour { private Vector2 startPosition; private bool dragEnable=false; // Use this for initialization void Start () { startPosition = transform.position ; } // Update is called once per frame void Update () { if (Input.GetMouseButton (0)) { EventSystem eventSystem = EventSystem.current; if (eventSystem.IsPointerOverGameObject ()){ dragEnable = true; } } else if (Input.GetMouseButtonUp (0)) { dragEnable=false; } if (dragEnable == true) { transform.position = Input.mousePosition; } else transform.position = Vector2.Lerp (transform.position, startPosition,20* Time.deltaTime); }//Update }
۹۴/۰۷/۰۴