unityVR アプリ開発入門という本を使って勉強しているのですが、その本でゲームの進行管理をabstructを使って抽象クラスを使って行っていたので、同じようにしてみたらSetActiveなどの操作全てが動きませんでした。エラーも全くでないです。
クラスを定義しているだけと思うので動かないのには納得がいきますが、どうすれば動くようになるのかが分からないです。
教えていただけると嬉しいです。
- etcは他のクラスと同じようなものです。
#コード h1
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class GameStateController : MonoBehaviour 6{ 7 public GameObject gameReady; 8 public RemainTimer timer; 9 public GameObject gameStart; 10 public GameObject gameOver; 11 public GameObject[] result; 12 public GameObject player; 13 public GameObject spawners; 14 15 abstract class BaseState 16 { 17 public GameStateController Controller { get; set; } 18 public enum StateAction 19 { 20 STATE_ACTION_WAIT, 21 STATE_ACTION_NEXT 22 } 23 public BaseState(GameStateController c) { Controller = c; } 24 public virtual void OnEnter() { } 25 public virtual StateAction OnUpdate() { return StateAction.STATE_ACTION_NEXT; } 26 public virtual void OnExit() { } 27 } 28 class ReadyState : BaseState 29 { 30 float timer; 31 public ReadyState(GameStateController c) : base(c) { } 32 public override void OnEnter() 33 { 34 Controller.gameReady.SetActive(true); 35 } 36 public override StateAction OnUpdate() 37 { 38 timer += Time.deltaTime; 39 if (timer > 5.0f) 40 { 41 return StateAction.STATE_ACTION_NEXT; 42 } 43 return StateAction.STATE_ACTION_WAIT; 44 } 45 public override void OnExit() 46 { 47 Controller.gameReady.SetActive(false); 48 } 49 } 50 class StartState : BaseState 51 { 52 etc 53 } 54 class PlayingState :BaseState 55 { 56 etc 57 } 58 } 59 class GameOverState : BaseState 60 { 61 etc 62 } 63 class ResultState : BaseState 64 { 65 etc }
回答2件
あなたの回答
tips
プレビュー