Beispiel #1
0
        void FixedUpdate()
        {
            foreach (var agent in agents)
            {
                if (Input.GetMouseButtonDown(0))
                {
                    Ray        camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
                    RaycastHit hit;
                    if (Physics.Raycast(camRay, out hit, 1000f))
                    {
                        //attempts to get the seek component on the agent
                        Seek seek = agent.GetComponent <Seek>();
                        Flee flee = agent.GetComponent <Flee>();
                        placeHolder.position = hit.point;
                        //update the transform's position

                        if (seek)
                        {
                            seek.target = placeHolder;
                        }

                        if (flee)
                        {
                            flee.target = placeHolder;
                        }
                    }
                }
            }
        }
        private void FixedUpdate()
        {
            if (Input.GetMouseButtonDown(0))
            {
                Ray        camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit mouseHit;
                if (Physics.Raycast(camRay, out mouseHit, 1000f))
                {
                    Flee flee = GetComponent <Flee>();
                    Seek seek = GetComponent <Seek>();
                    placeholdPoint.position = mouseHit.point;

                    foreach (var agent in agents)
                    {
                        if (seek)
                        {
                            seek.target = placeholdPoint;
                        }
                        else if (flee)
                        {
                            flee.target = placeholdPoint;
                        }
                    }
                }
            }
        }