このスクリプトをunityに導入すると、Assets\script\Human123.cs(271,6): error CS1513: } expectedと出ます
対処法を教えて下さい
追記
最後に一個}を付け足すと,CS0103などのエラーが10個付け足されます
参考動画はこちらを参考にしています https://www.youtube.com/watch?v=E5NSgXNgKvY
c#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using UnityEngine.AI; 5 6public class Human123 : MonoBehaviour 7{ 8 9 10 11 12 13 enum State 14 { 15 sleep, 16 gotoToilet, 17 washHand, 18 doNothing, 19 eat, 20 starveToDeath 21 } 22 23 enum DesireType 24 { 25 sleep, 26 eat, 27 toilet 28 } 29 30 class Desire 31 { 32 public DesireType type { get; private set; } 33 public float value; 34 35 public Desire(DesireType _type) 36 { 37 type = _type; 38 value = 0f; 39 } 40 41 class Desires 42 { 43 public List<Desire> desireList { get; private set; } = new List<Desire>(); 44 45 public Desire GetDesire(DesireType type) 46 { 47 foreach (Desire desire in desireList) 48 { 49 if (desire.type == type) 50 { 51 return desire; 52 } 53 } 54 55 return null; 56 57 } 58 59 60 61 public void SortDesire() 62 { 63 desireList.Sort((desire1, desire2) => desire2.value.CompareTo(desire1.value)); 64 } 65 66 67 68 public Desires() 69 { 70 int desireNum = System.Enum.GetNames(typeof(DesireType)).Length; 71 72 for (int i = 0; i < desireNum; i++) 73 { 74 DesireType type = System.Enum.ToObject(typeof(DesireType), i); 75 Desire newDesire = new Desire(type); 76 77 desireList.Add(newDesire); 78 } 79 } 80 } 81 82 Desires desires = new Desires(); 83 84 85 86 87 88 float sleepDisireUpSpeed = 15f; 89 float sleepDesireDownSpeed = 5f; 90 91 92 float toiletDesireUpSpeed = 8f; 93 float toiletTime = 2f;//トイレにかかる時間 94 95 float handBacteria = 0;//手の汚れ 0-1 トイレから出たら1になる 96 float handWashSpeed = 2f;//手を洗うスピード 97 98 99 float hungrySpeed = 10; 100 float eatspeed = 3; 101 102 State curretState = State.doNothing; 103 bool stateEnter = true; 104 105 void ChangeState(State newState) 106 { 107 curretState = newState; 108 stateEnter = true; 109 } 110 private void Update() 111 { 112 if (curretState != State.sleep) 113 { 114 desires.GetDesire(DesireType.sleep).value += Time.deltaTime / sleepDisireUpSpeed; 115 } 116 117 if (curretState != State.gotoToilet) 118 { 119 desires.GetDesire(DesireType.toilet).value += Time.deltaTime / toiletDesireUpSpeed; 120 } 121 122 if (curretState != State.eat) 123 { 124 desires.GetDesire(DesireType.eat).value += Time.deltaTime / hungrySpeed; 125 } 126 127 if (curretState != State.starveToDeath && eatDesire >= 2.0f) 128 { 129 ChangeState(State.starveToDeath); 130 return; 131 } 132 133 134 135 136 137 switch (curretState) 138 { 139 case State.starveToDeath: 140 #region 141 if (stateEnter) 142 { 143 stateEnter = false; 144 Debug.Log("死んだ"); 145 } 146 #endregion 147 break; 148 149 case State.doNothing: 150 #region 151 if (stateEnter) 152 { 153 stateEnter = false; 154 Debug.Log("暇だなnanananananaー"); 155 } 156 157 158 159 160 if (eatDesire >= 1) 161 { 162 ChangeState(State.eat); 163 return; 164 } 165 166 if (toiletDesire >= 1) 167 { 168 ChangeState(State.gotoToilet); 169 return; 170 } 171 172 if (sleepDisire >= 1) 173 { 174 ChangeState(State.sleep); 175 return; 176 } 177 #endregion 178 break; 179 180 181 182 case State.eat: 183 #region 184 if (stateEnter) 185 { 186 stateEnter = false; 187 Debug.Log("腹減ったから、飯を食おう"); 188 189 } 190 191 eatDesire -= Time.deltaTime / eatspeed; 192 193 if (eatDesire <= 0) 194 { 195 ChangeState(State.doNothing); 196 } 197 #endregion 198 break; 199 200 201 202 case State.gotoToilet: 203 #region 204 if (stateEnter) 205 { 206 stateEnter = false; 207 Debug.Log("トイレなうー"); 208 handBacteria += 1; 209 } 210 211 212 toiletDesire -= Time.deltaTime / toiletTime; 213 214 if (toiletDesire <= 0) 215 { 216 ChangeState(State.washHand); 217 return; 218 } 219 #endregion 220 break; 221 222 223 224 case State.washHand: 225 #region 226 if (stateEnter) 227 { 228 stateEnter = false; 229 Debug.Log("すっきりした 手を洗おう"); 230 231 } 232 233 handBacteria -= Time.deltaTime / handWashSpeed; 234 235 if (handBacteria <= 0) 236 { 237 ChangeState(State.doNothing); 238 return; 239 } 240 #endregion 241 break; 242 243 case State.sleep: 244 #region 245 if (stateEnter) 246 { 247 stateEnter = false; 248 Debug.Log("寝るかな"); 249 } 250 251 sleepDisire -= Time.deltaTime / sleepDesireDownSpeed; 252 253 if (sleepDisire <= 0) 254 { 255 ChangeState(State.doNothing); 256 return; 257 } 258 #endregion 259 break; 260 261 262 263 264 265 } 266 267 } 268 269 270 271 } 272}
質問を編集して、入力欄上部の<code>を押してコードはそこに入力してください
回答2件
あなたの回答
tips
プレビュー