前提・実現したいこと
ここに質問の内容を詳しく書いてください。
Unityでジグソーパズルを作成しています。
自分で作成した.objのピースをドラッグで移動しようとしているのですが、うまくいきません。
とりあえず、ネットにあったソースを使ってみたのですがだめでした。
発生している問題・エラーメッセージ
NullReferenceException: Object reference not set to an instance of an object PieceController.OnMouseDown () (at Assets/PieceController.cs:14)
該当のソースコード
C#
1 private Vector3 screenPoint; 2 private Vector3 offset; 3 4 void OnMouseDown() 5 { 6 screenPoint = Camera.main.WorldToScreenPoint(transform.position); 7 8 float x = Input.mousePosition.x; 9 float y = Input.mousePosition.y; 10 11 offset = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(x, y, screenPoint.z)); 12 } 13 14 void OnMouseDrag() 15 { 16 float x = Input.mousePosition.x; 17 float y = Input.mousePosition.y; 18 19 Debug.Log(x.ToString() + " - " + y.ToString()); 20 21 Vector3 currentScreenPoint = new Vector3(x, y, screenPoint.z); 22 23 Vector3 currentPosition = Camera.main.ScreenToWorldPoint(currentScreenPoint) + offset; 24 25 transform.position = currentPosition; 26 }
試したこと
様々なソースコードで試しました。
補足情報(FW/ツールのバージョンなど)
Unity Personal 最新バージョン, Visual Stadio2017
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/11/15 14:41
2018/11/15 21:25