Esempio n. 1
0
    private void Update()
    {
        if (Time.time - _lastUpdateTime > _updateInterval)
        {
            foreach (var npc in _npcs)
            {
                if (npc.State == NpcState.Decayed)
                {
                    npc.State = NpcState.Normal;
                    npc.transform.position = Util.CalculateWorldBox(_borderOffset).GetRandomVectorInBox();
                    npc.SetVisibility(true);
                }

                if (npc.State != NpcState.Killed && !npc.IsMoving && Util.CalculateRandomEvent(_playerMoveProbability))
                {
                    var pos = npc.Get2DPosition();

                    var lowerX = pos.x - _playerMoveBoxWidth / 2;
                    var lowerY = pos.y - _playerMoveBoxHeight / 2;
                    var upperX = pos.x + _playerMoveBoxWidth / 2;
                    var upperY = pos.y + _playerMoveBoxHeight / 2;

                    var moveBox = new Box(lowerX, lowerY, upperX, upperY);
                    moveBox.FitBox(Util.CalculateWorldBox(_borderOffset));

                    var newPos = moveBox.GetRandomVectorInBox();

                    npc.MoveTo(newPos);
                }
            }

            _lastUpdateTime = Time.time;
        }
    }