void FixedUpdate()
        {
            if (Input.GetMouseButtonDown(0))
            {
                foreach (var agent in agents)
                {
                    Ray        camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
                    RaycastHit hit;
                    if (Physics.Raycast(camRay, out hit, 1000f))
                    {
                        // Try to get seek component agent
                        Seek seek = agent.GetComponent <Seek>();
                        Seek flee = agent.GetComponent <Seek>();

                        // update the transforms position
                        placeHolderPoint.position = hit.point;

                        // if seek is not null
                        if (seek)
                        {
                            // update seek's target(which you might not need to do)
                            seek.target = placeHolderPoint;
                        }
                        if (flee)
                        {
                            // update flee's target(which you might not need to do)
                            flee.target = placeHolderPoint;
                        }
                    }
                }
            }
        }
Пример #2
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;
                        }
                    }
                }
            }
        }