setdestination can only be called on an active agent that has been placed on a navmesh
Unity/찾아본것 2019. 5. 3. 15:27
네브메쉬가 적용된 캐릭터의 좌표를 동적으로 할당할때 생기는 문제
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.AI; using UnityEngine.UI; public class TestMove : MonoBehaviour { public Button btnStart; public GameObject StartPos; public GameObject EndPos; private GameObject hobPrefab; private GameObject hob; private NavMeshAgent agent; private bool nope; private void Awake() { this.hobPrefab = Resources.Load<GameObject>("Hoverbuggy"); } private void Start() { this.StartGame(); } private void StartGame() { StartCoroutine(this.StartGameImpl()); } private IEnumerator StartGameImpl() { while (true) { this.btnStart.onClick.AddListener(() => { if(!nope) { this.nope = true; this.hob = Instantiate(hobPrefab); this.agent = this.hob.GetComponent<NavMeshAgent>(); this.agent.enabled = false; this.hob.transform.position = new Vector3(this.StartPos.transform.position.x, 0.3f, this.StartPos.transform.position.z); this.agent.enabled = true; this.agent.destination = this.EndPos.transform.position; } }); yield return null; } } } | cs |
44~49번줄
캐릭터를 인스턴스화 하고, 네브메쉬를 비활성화 한 뒤, 새로운 Vector3를 주고 네브메쉬를 다시 활성화한다.
'Unity > 찾아본것' 카테고리의 다른 글
Unity Custom Inspector 커스텀 인스펙터 (0) | 2019.07.22 |
---|---|
<화면 나누기> ViewportRect사용 (0) | 2019.06.14 |
유니티 현재의 씬 다시 불러오기 (0) | 2019.05.02 |
Unity Canvas (0) | 2019.04.24 |
Animator Length 구하기 API (0) | 2019.04.23 |