示例#1
0
    // Use this for initialization
    void Start()
    {
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit objectClicked;

        if (Physics.Raycast(ray, out objectClicked) && objectClicked.transform.tag != "Player")
        {
            Vector3 target = objectClicked.transform.tag == "Ground" ? objectClicked.point : objectClicked.transform.position;
            MoveTowardsDirection movement = gameObject.GetComponent <MoveTowardsDirection>();
            movement.direction = MovementHelper.calculateNormalizedDirection(transform.position, target);
        }
    }
示例#2
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButton(1))
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit objectClicked;

            if (Physics.Raycast(ray, out objectClicked) && objectClicked.transform.tag != "Player")
            {
                destination         = objectClicked.point;
                destination.y       = transform.position.y;
                _movement.direction = MovementHelper.calculateNormalizedDirection(transform.position, destination);
            }
        }

        if (Vector3.Distance(destination, transform.position) <= distanceTolerance)
        {
            _movement.direction = Vector3.zero;
        }
    }
示例#3
0
 // Update is called once per frame
 void Update()
 {
     _movement.direction = MovementHelper.calculateNormalizedDirection(transform.position, _target.transform.position);
 }