當前位置: 首頁>>代碼示例>>C#>>正文


C# NavMeshAgent.GetComponent方法代碼示例

本文整理匯總了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;
    }
開發者ID:jsimoesjr,項目名稱:Unity,代碼行數:9,代碼來源:PlayerControl.cs

示例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);

                    }

                }
    }
開發者ID:CG-F15-24-Rutgers,項目名稱:UnityProjects,代碼行數:50,代碼來源:Player_Move.cs

示例3: Start

    // Use this for initialization
    void Start () {
        Player = GameManager.PlayerCharacter.GetComponent<NavMeshAgent>();
        playerMove = Player.GetComponent<NoahMove> ();
        speechBubble = Player.GetComponentInChildren<SpeechBubble>();

    }
開發者ID:imann24,項目名稱:cs327-bestmobilegameever,代碼行數:7,代碼來源:NoahNavPlane.cs

示例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;

                    }

                }
            }
        }
    }
開發者ID:CG-F15-2-Rutgers,項目名稱:UnityProjects,代碼行數:101,代碼來源:RayCast.cs


注:本文中的UnityEngine.NavMeshAgent.GetComponent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。