本文整理汇总了C#中UnityEngine.NavMeshAgent.GetComponent方法的典型用法代码示例。如果您正苦于以下问题:C# NavMeshAgent.GetComponent方法的具体用法?C# NavMeshAgent.GetComponent怎么用?C# NavMeshAgent.GetComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.NavMeshAgent
的用法示例。
在下文中一共展示了NavMeshAgent.GetComponent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
//Vector3 oldpos;
//Vector3 newpos;
void Start()
{
player = GetComponent<NavMeshAgent>();
anim = player.GetComponent<Animator> ();
//oldpos = newpos = transform.position;
}
示例2: Update
// Update is called once per frame
void Update()
{
hor = Input.GetAxis ("Horizontal1");
ver = Input.GetAxis ("Vertical1");
RaycastHit hit;
//float moveHorizontal = Input.GetAxis("horizontal");
//float moveVertical = Input.GetAxis("vertical");
//Select the agent to move and move
if (Input.GetMouseButtonDown (0))
{
print ("1");
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
//select Agent
if (Physics.Raycast (ray, out hit, 300))
{
print ("2");
if (hit.transform.CompareTag ("capsule")) {
print ("3");
agent = hit.collider.gameObject.GetComponent<NavMeshAgent> ();
anim = agent.GetComponent<Animator> ();
}
print ("anim" + anim);
}
}
if (anim != null)
{ print ("4");
anim.SetFloat("speed",ver);
anim.SetFloat("direction",hor);
AnimatorStateInfo stateInfo = anim.GetCurrentAnimatorStateInfo(0);
if(Input.GetKeyDown(KeyCode.Space)&& stateInfo.fullPathHash == runHash)
{
anim.SetTrigger(jumpstate);
}
if(anim.IsInTransition(0))
{
anim.SetBool("jump",false);
}
}
}
示例3: Start
// Use this for initialization
void Start () {
Player = GameManager.PlayerCharacter.GetComponent<NavMeshAgent>();
playerMove = Player.GetComponent<NoahMove> ();
speechBubble = Player.GetComponentInChildren<SpeechBubble>();
}
示例4: Update
//.........这里部分代码省略.........
CameraCurrentlySelected.text = "Camera position 4 selected!";
ThingsHappening.text = "Number Key '4' Pressed";
agentToMove = CameraPosition4;
}
if (Input.GetKeyDown ("5")) {
Debug.Log ("Camera set to position 5");
CameraCurrentlySelected.text = "Camera position 5 selected!";
ThingsHappening.text = "Number Key '5' Pressed";
agentToMove = CameraPosition5;
}
if (Input.GetKeyDown ("6")) {
Debug.Log ("Camera set to position 6");
CameraCurrentlySelected.text = "Camera position 6 selected!";
ThingsHappening.text = "Number Key '6' Pressed";
agentToMove = CameraPosition6;
}
if (Input.GetKeyDown ("7")) {
Debug.Log ("Camera set to position 7");
CameraCurrentlySelected.text = "Camera position 7 selected!";
ThingsHappening.text = "Number Key '7' Pressed";
agentToMove = CameraPosition7;
}
/***
* If left mouse button is pressed, and agent is pressed, add it to the list;
***/
if (Input.GetButtonDown ("Fire1")) {
ThingsHappening.text = "Left Mouse Button selected!";
if (Physics.Raycast (ray, out hit) == true) {
if (hit.transform.gameObject.CompareTag("Player")) {
Debug.Log("--------LEFT CLICK---------");
string name = hit.collider.gameObject.name;
agent_names.Add (name);
Debug.Log (hit.collider.gameObject.name);
Debug.Log (agent_names[agent_names.Count-1]);
//printContents(agent_names);
AgentCurrentlySelected.text = "Agent Selected:" + agent_names[agent_names.Count-1].ToString ();
}
if (hit.transform.gameObject.CompareTag("Movable")) {
Debug.Log ("Movable Object clicked");
if (movable_objects.Count != 0){
movable_objects.RemoveAt (0);
}
string name_of_movable_object = hit.collider.gameObject.name;
movable_objects.Add(name_of_movable_object);
Debug.Log("Count of movable Objects: " + movable_objects[movable_objects.Count-1]);
MovableObjectSelected.text = "Movable Object Selected:" + movable_objects[0].ToString ();
}
}
}
/****
This code takes in a right mouse click, and determies of the object which was clicked is a surface (ground). If it is a surface, it then measures if any agents were selected.
If they werent, the camera offset is set to default, which is what the simulations starts in. If agents were selected, a loop goes through the cntents of the list and navigates
each one through the map.
****/
if(Input.GetButtonDown ("Fire2") || Input.GetButton ("Fire2")){
ThingsHappening.text = "Right mouse button pressed!";
if(Physics.Raycast (ray,out hit) == true){
if(hit.transform.gameObject.CompareTag ("Ground")){
Debug.Log("--------RIGHT CLICK---------");
if (agent_names.Count != null){
ThingsHappening.text = "Agent currently moving to position!";
Debug.Log("List of agents not empty! Moving added agents...");
for(int i = 0; i < agent_names.Count; i ++){
agentToMove = GameObject.Find(agent_names[i]);
Debug.Log ("Agent moving successfully. Probably. Maybe.");
agent = agentToMove.GetComponent<NavMeshAgent>();
agent.SetDestination (hit.point);
agent.GetComponent<Animator>().SetFloat ("vertical_speed",1);
Debug.Log (agent.transform.position);
Debug.Log (hit.point);
}
}
if(agent_names.Count == null){
ThingsHappening.text = "No agents selected to move!";
Debug.Log("List empty! Select agents to move...");
agentToMove = CameraPosition;
}
}
}
}
}