現在unityでゲームを作成しています。
sliderを使用してタップしたらゲージを増やしたいのですが、どのようにすれば良いかわかりません。
教えていただけたら嬉しいです。
またこのコードで実行すると、Assets/tapbutton.cs(47,9): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statementとエラーが出ます。
c#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using UnityEngine.UI; 5 6public class tapbutton : MonoBehaviour 7{ 8 9 10 // ボタンを定義 11 public Button BookButton; 12 // テキストエリアを定義 13 public Text countbook; 14 //カウンター数を記録 15 public int CountNum; 16 17 GameObject gameobject; 18 19 // Use this for initialization 20 void Start() 21 { 22 23 24 countbook.text = "0"; 25 CountNum = 0; 26 27 28 29 BookButton.onClick.AddListener(bookOnClick); //本を押したときに呼ばれるメソッドを指定 30 31 32 } 33 34 // Update is called once per frame 35 void Update() 36 { 37 38 } 39 40 // ボタンが押されたときに呼ばれるメソッド 41 void bookOnClick() 42 { 43 CountNum++; // カウンター変数を加算 44 TextAreaUpdate(CountNum); 45 46 GameObject director = GameObject.Find("GameDirector"); 47 director.GetComponent<GameDirector>().IncreaseTap; 48 49 } 50 51 // テキストエリアの文字をアップデートするメソッド 52 void TextAreaUpdate(int num) 53 { 54 countbook.text = CountNum.ToString(); 55 } 56 57}
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class GameDirector : MonoBehaviour { Slider HpGauge; // Start is called before the first frame update void Start() { HpGauge = GameObject.Find("sinSlider").GetComponent<Slider>(); } public void IncreaseTap() { HpGauge.value += 1; } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/08/14 07:41