お世話になっております。
Unityのスクリプトに関してのご質問になります。
【やりたい事】
例えば、画面上のオブジェクトを左手でスライドし移動させながら、右手でボタンオブジェクトをタップし別の動作(弾を撃つ等)をさせたい。
【状況】
プレイヤーオブジェクトをスライド移動させながらボタンオブジェクトをタップすると、ボタンオブジェクトタップ時の座標が取得されてしまい、プレイヤーオブジェクトの位置が変わってしまう。
上記に関して、ボタンオブジェクトタップ時の座標が、プレイヤーオブジェクト移動時の座標に干渉しないようにするには、どのような実装を行えばよろしいでしょうか。
該当ソースコードは下記になります。
Player
1void OnMouseDrag() 2{ 3 Vector3 objectPointInScreen = Camera.main.WorldToScreenPoint(this.transform.position); 4 5 Vector3 mousePointInScreen 6 = new Vector3(Input.mousePosition.x, 7 8 Input.mousePosition.y, 9 10 objectPointInScreen.z 11 12 ); 13 14 Vector3 mousePointInWorld = Camera.main.ScreenToWorldPoint(mousePointInScreen); 15 this.transform.position = mousePointInWorld; 16} 17 18//ButtonオブジェクトのInspectornにて、「on Click()」で呼び出すメソッドとして設定しています。 19public void Shoot() 20{ 21 GameObject newBullet = Instantiate(Arrow,SpawnPoint.position,Quaternion.identity)as GameObject; 22 newBullet.GetComponent<Rigidbody2D>().AddForce(Vector3.right * power); 23} 24
以上、よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/09/06 14:32