前提・実現したいこと
Unity2Dでロングタップした場所にプレハブを生成したいのですが、今記述している内容ですとプレハブが毎フレーム生成されてしまううえに、実機とエディターで処理が分かれてしまい確認の際不便なのですが、他に良い記述の仕方はないでしょうか。
TouchScript9.0というアセットも試してみようと思い使い方を調べてみたのですが、長押し(ロングタップ)を検出するためのLongPressGestureというスクリプトが見つからず、もしこちらについても詳しくご存知の方がいましたらご教授いただけると幸いです。
該当のソースコード
C#
1public class Player : MonoBehaviour 2{ 3 public GameObject Prefab; 4 private Vector3 clickPosition; 5 6//-------中略------- 7 8void Update() 9 { 10 if (Input.GetMouseButton(0)) 11 { 12 clickPosition = Input.mousePosition; 13 clickPosition.z = 10f; 14 Instantiate(Prefab, Camera.main.ScreenToWorldPoint(clickPosition), Prefab.transform.rotation); 15 Debug.Log("ロングクリック"); 16 } 17 18 if (Input.touchCount > 0) 19 { 20 Touch touch = Input.GetTouch(0); 21 22 if (touch.phase == TouchPhase.Moved) 23 { 24 Vector3 touchPosition = touch.position; 25 Vector3 worldTouchPosition = Camera.main.ScreenToWorldPoint(touchPosition); 26 Debug.Log("ロングタップ"); 27 } 28 } 29 }
補足情報(FW/ツールのバージョンなど)
Unity2018.3.5f1
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。