###前提・実現したいこと
趣味でUnity2Dの勉強をしている初心者です。また、初めてteratailに投稿するので、色々と不明点がありましたら申し訳ありません。
オブジェクトのドラッグ&ドロップをできるようにしたいのですが、エラーメッセージが表示されて、できません。
エラーメッセージとソースコードは以下です。
###発生している問題・エラーメッセージ
NullReferenceException: Object reference not set to an instance of an object ButtonClick.OnMouseDrag () (at Assets/ButtonClick.cs:18) UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32)
###該当のソースコード
//The original code is obtained from http://answers.unity3d.com/questions/581904/2d-mode-trying-to-make-a-sprite-dragable.html for my future reference. //By Shatcore 2013 using UnityEngine; using System.Collections; public class ButtonClick : MonoBehaviour { float x; float y; // Update is called once per frame void Update(){ x = Input.mousePosition.x; y = Input.mousePosition.y; } void OnMouseDrag(){ transform.position = Camera.main.ScreenToWorldPoint(new Vector3(x,y,10.0f)); } }
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/08/15 10:30