前提・実現したいこと
Unity、C#初心者です。
アタッチしているゲームオブジェクトのタッチをやめた時、自身を破壊してcardprefabをBattlereaに出すスクリプトなのですが、他のゲームオブジェクトをタッチしている時に離した場合にもif内の処理が実行されてしてしまいます。
このスクリプトをアタッチしているオブジェクトのタッチをやめた時だけ処理をさせたいのですが、どうすれば良いのでしょうか?
該当のソースコード
C#
1using UnityEngine; 2using UnityEngine.EventSystems; 3 4public class CardUnit : MonoBehaviour, IDragHandler 5{ 6 7 public GameObject BattleErea; 8 public GameObject cardprefab; 9 10 public void OnDrag(PointerEventData data) 11 { 12 Vector3 TargetPos = Camera.main.ScreenToWorldPoint(data.position); 13 TargetPos.z = 0; 14 transform.position = TargetPos; 15 } 16 void Update() { 17 18 if (Input.GetMouseButtonUp(0)) 19 { 20 GameObject child = Instantiate(cardprefab); 21 child.transform.SetParent(BattleErea.transform, false); 22 23 Destroy(this.gameObject); 24 Debug.Log("召喚"); 25 26 } 27 } 28}
###試したこと
解決方法を調べましたが、表現方法が悪いのか回答は得られませんでした。
名称や条件を変更しましたが、やはり全てが処理される結果になりました。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/03/23 00:59