생활
c# enum을 이용해서 스위치문을 랜덤하게 이동하는 방법
using System.Collections;using System.Collections.Generic;using UnityEngine;public class PigMove : MonoBehaviour{ enum state { Eat = 0, Move = 1, Run = 2, Dead = 3} Rigidbody pig; Random rand = new Random(); state State = rand.Next(0, 4); void Start() { } void Update() { switch(State) { case state.Eat: break; case state.Move: StartCoroutine(MovePig()); break; case state.Run: break; case state.Dead: break; } } IEnumerator MovePig() { pig = GetComponent<Rigidbody>(); while (true) { float dir1 = Random.Range(-10f, 10f); float dir2 = Random.Range(-10f, 10f); yield return new WaitForSeconds(5); pig.velocity = new Vector3(dir1, 0.5f, dir2); } } }제가 짠 코드는 위와 같습니다. 이렇게 하면 될 줄 알았는데 안 되네요..ㅠㅠ 유니티로 동물의 행동 패턴을 만들려고 해요. 알려주시면 감사드리겠습니다.
아직 답변이 없어요.