Unityを利用しています。
GameObject①(Quizz3)にアタッチされたスクリプト①(Quizz3)からGameObject②(Lion)にアタッチされたスクリプト②(PlayerController)を呼び出し実行したいです
この機能を実装中に以下のエラーメッセージが発生しました。
以下の2つのエラーが表示される。
Assets\Scripts\Quizz3.cs(39,35): error CS0176: Member 'GameObject.Find(string)' cannot be accessed with an instance reference; qualify it with a type name instead
Assets\Scripts\Quizz3.cs(40,16): error CS1061: 'PlayerController' does not contain a definition for 'Log' and no accessible extension method 'Log' accepting a first argument of type 'PlayerController' could be found (are you missing a using directive or an assembly reference?)
該当のソースコード
Unity
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class Quizz3 : MonoBehaviour 6{ 7 private void Update() 8 { 9 if (Input.GetMouseButtonDown(0)) 10 { 11 RayCast(); 12 } 13 14 void RayCast() 15 { 16 //↓Rayの作成↓ 17 // 18 Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); 19 RaycastHit hit; 20 21 Debug.DrawRay(ray.origin, ray.direction * 10, Color.red, 5); 22 23 24 if (Physics.Raycast(ray, out hit, 10.0f)) 25 { 26 PlayerController cs = gameObject.Find("Lion").GetComponent<PlayerController>(); 27 cs.Log(); 28 } 29 } 30 } 31}
###解説方法についてご教授いただけませんでしょうか。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/03/26 02:05
2022/03/26 06:17