前提・実現したいこと
UnityでCubeの動いた跡に線を引きたい(3D)。
発生している問題・エラーメッセージ
NullReferenceException: Object reference not set to an instance of an object MopController.Update () (at Assets/MopController.cs:23)
該当のソースコード
using System.Collections; using System.Collections.Generic; using UnityEngine; public class MopController : MonoBehaviour { private GameObject Cube; // Use this for initialization void Start () { GameObject Mop = GameObject.Find("Cube"); } // Update is called once per frame void Update () { if (Input.GetMouseButtonDown(0)) { Vector3 mousePos = Input.mousePosition; mousePos.z = 10.0f; Debug.Log(mousePos); Vector3 MouseP = Camera.main.ScreenToWorldPoint(mousePos); if (Input.GetMouseButton(0)) { Cube.transform.Translate(MouseP); } } } }
試したこと
スクリプトをMainCameraにアタッチしたり、Cubeにアタッチしたりいろいろしましたが、よくわかりません。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/11/14 01:25