GoTo() public method

public GoTo ( Vector3 target, bool isRunning ) : void
target Vector3
isRunning bool
return void
Example #1
0
        private IEnumerator Roam()
        {
            while (!target)
            {
                if (owner == null)
                {
                    yield return(null);
                }
                if (!IsOwnerTooFar())
                {
                    Unit nearestEnemy = AIUtils.GetNearestEnemy(_unit, agroRadius);
                    if (nearestEnemy == null)
                    {
                        nearestEnemy = AIUtils.GetNearestEnemy(owner, agroOwnerRadius);
                    }
                    if (nearestEnemy != null)
                    {
                        Attack(nearestEnemy);
                        yield break;
                    }
                }

                var newPosition = owner.iso.pos + _maintainOffset;
                _unit.GoTo(newPosition);
                yield return(new WaitForSeconds(Random.Range(0.1f, 0.5f)));
            }
        }
Example #2
0
    IEnumerator WalkAround()
    {
        yield return(new WaitForEndOfFrame());

        while (true)
        {
            var target = _initialPosition + new Vector2(Random.Range(-8f, 8f), Random.Range(-8f, 8f));
            _unit.GoTo(target);
            yield return(new WaitForSeconds(Random.Range(1f, 3f)));
        }
    }
Example #3
0
        private IEnumerator Roam()
        {
            while (!target)
            {
                Unit nearestEnemy = AIUtils.GetNearestEnemy(_unit, viewRadius);
                if (nearestEnemy != null)
                {
                    Attack(nearestEnemy);
                    yield break;
                }

                var newPosition = _unit.iso.pos + new Vector2(Random.Range(-8f, 8f), Random.Range(-8f, 8f));
                _unit.GoTo(newPosition);
                yield return(new WaitForSeconds(Random.Range(1f, 2f)));
            }
        }
Example #4
0
        public override void Operate(Unit unit)
        {
            var targetWarp = FindTargetWarp();

            if (targetWarp == null)
            {
                Debug.LogError("Target warp wasn't found");
                return;
            }

            ScreenFader.SetToBlack();
            ScreenFader.FadeToClear();
            var target = Iso.MapToIso(targetWarp.transform.position);

            unit.InstantMove(target);
            unit.GoTo(target + new Vector3(targetWarp.info.exitWalkX, targetWarp.info.exitWalkY));
        }
Example #5
0
    // Update is called once per frame
    void FixedUpdate()
    {
        /*Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         * RaycastHit2D hit;*/
        if (Input.GetButtonDown("RClick"))
        {
            Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Vector2 dir      = mousePos - transform.position;

            /*hit = Physics2D.Raycast(transform.position, dir, Vector2.Distance(transform.position, mousePos),  unwalkableMask);
             * if(hit.collider == null)
             * {
             *  unit.followingPath = false;
             *  StartCoroutine(GoToMouse(mousePos, dir));
             * }
             * else
             * {*/
            unit.GoTo(mousePos);

            /*}
             * Debug.DrawRay(transform.position, dir, Color.green);*/
        }
    }