エラー内容は以下です。
UnassignedReferenceException: The variable method43 of lefthand4 has not been assigned.
You probably need to assign the method43 variable of the lefthand4 script in the inspector.
UnityEngine.GameObject.GetComponent[T] () (at <cc0084eac53d486888f184f29b10b051>:0)
lefthand4.Update () (at Assets/Scenes/Script/Scene4/lefthand4.cs:24)
インスペクター画面にmethod43をアタッチしてないというエラーだと思いますが、インスペクター画面にはアタッチしてあることは確認済みです。ゲームを実行するとこのエラーが貯まってしまいます。
スクリプトに原因があるのでしょうか?
コード using System.Collections; using System.Collections.Generic; using UnityEngine; public class lefthand4 : MonoBehaviour { public GameObject method43; public Camera standcamera; // Start is called before the first frame update void Start() { standcamera.gameObject.SetActive(false); } // Update is called once per frame void Update() { //method43が表示されている時にstandcameraが表示される。 if (method43.GetComponent<Renderer>().enabled == true) { standcamera.gameObject.SetActive(true); } } void OnMouseDrag() { //method43が表示されていてる時に動かせる。 if (method43.GetComponent<Renderer>().enabled == true) { Vector3 objectPointInScreen = Camera.main.WorldToScreenPoint(this.transform.position); Vector3 mousePointInScreen = new Vector3(Input.mousePosition.x, Input.mousePosition.y, objectPointInScreen.z); Vector3 mousePointInWorld = Camera.main.ScreenToWorldPoint(mousePointInScreen); mousePointInWorld.z = this.transform.position.z; this.transform.position = mousePointInWorld; } } }
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/10/20 01:31