public GameNavmeshHelper(Transform parent) { m_parent = parent; //添加一个子GameObject到parent中,用于寻路 m_navAgent = parent.GetComponentInChildren <NavMeshAgent>(); if (m_navAgent != null) { m_navGo = m_navAgent.gameObject; m_navAgent.enabled = false; } else { m_navGo = new GameObject(); UnityTools.ChangeObjectParentDontChangeLocalTransform(m_navGo.transform, parent); ResetPositionToCLoseToNavMesh(); m_navAgent = m_navGo.AddComponent <NavMeshAgent>(); m_navAgent.enabled = false; m_navAgent.height = 2f; m_navAgent.radius = 1f; } }