はじめに、
皆様も同じだと思いますが、私も時間がないためできるだけ早めの回答を待っています。
また、私はまだ初めたての初心者で、あまり理解できていない部分があるため、よくわからない部分があるかもしれません。ご了承ください。
そして、できるだけわかりやすい説明をしてくれると幸いです。
内容
unityで3dゲームを作っており、bool関数を別ファイルに渡したいのですが、エラーが出て困っています。
コード1
DeviceLoad.cs
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class DeviceLoad : MonoBehaviour 6{ 7 // Start is called before the first frame update 8 void Start() 9 { 10 11 } 12 13 // Update is called once per frame 14 void Update() 15 { 16 17 } 18 19 internal bool SearchPlatform() 20 { 21 if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer) 22 { 23 return true; 24 } 25 else 26 { 27 return false; 28 } 29 30 } 31} 32
コード2
Switch_Block.cs
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class Switch_Block : MonoBehaviour 6{ 7 // Start is called before the first frame update 8 void Start() 9 { 10 bool Platform; 11 Platform = DeviceLoad.SearchPlatform(); 12 } 13 14 // Update is called once per frame 15 void Update() 16 { 17 18 } 19}
上記の「Switch_Block.cs」内の11行目のエラーで
エラー CS0120 静的でないフィールド、メソッド、またはプロパティ 'DeviceLoad.SearchPlatform()' で、オブジェクト参照が必要です。
と表示されていて、解決できず、困っています。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/09/01 10:31 編集