前提・実現したいこと
オブジェクトRight
をクリックしたときにTextのScore
に100点ずつ加算していく。
発生している問題・エラーメッセージ
Assets\Play\Sample\Script\Right.cs(22,48): error CS0176: Member 'Right.Point' cannot be accessed with an instance reference; qualify it with a type name instead
該当のソースコード
C#
1using UnityEngine; 2using UnityEngine.EventSystems; 3using UnityEngine.UI; 4 5public class Right : MonoBehaviour, IPointerClickHandler 6{ 7 static int Point = 0; 8 GameObject Score; 9 void Start() 10 { 11 this.Score = GameObject.Find("Score"); 12 } 13 14 public void OnPointerClick(PointerEventData eventData) 15 { 16 if (true) 17 { 18 Point += 100; 19 Debug.Log("CHECK NOW"); 20 Destroy(gameObject); 21 } 22 this.Score.GetComponent<Text>().text = this.Point.ToString("F0"); 23 24 } 25}
補足
おそらくStatic
関数が原因でスクリプトで下から四段目のthis.Point
の部分でエラーが発生したと思われるが対処方法が分からない。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。