###前提・実現したいこと
インスタンスのメソッドにアクセスしようとすると、エラーが出てしまいます。(おそらくアクセス権限のエラー。)
publicで定義しているので、原因、対処法がわかりません。
ご教授お願いします。
###試したこと
Sampleクラスのスクリプトを、空のゲームオブジェクトにアタッチさせて、
Hogeクラスのスクリプトは、ゲームオブジェクトにアタッチさせていません。
C#
1using UnityEngine; 2using System.Collections; 3 4public class Sample: MonoBehaviour{ 5 6 void Start () { 7 Hoge.output (); //Hoge 8 9 Hoge hoge = new Hoge (); 10 hoge.output2 (); //ここでエラー。 11 } 12} 13
C#
1using UnityEngine; 2using System.Collections; 3 4public class Hoge { 5 6 public static void output(){ 7 Debug.Log ("Hoge"); 8 } 9 10 public void output2(){ 11 Debug.Log ("Hoge2"); 12 } 13}
###発生している問題・エラーメッセージ
Assets/Sample.cs(11,8): error CS0122: `Hoge.output2()' is inaccessible due to its protection level
Sampleクラスの「hoge.output2 ();」をコメントアウトすると、エラーは起きません。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/02/05 07:48