Esempio n. 1
0
        public bool CheckAndMoveToNextPathNode()
        {
            if (_currentPath.Count <= 0)
            {
                return(false);
            }

            Room          currentRoom  = _character.CurrentRoom;
            Node          nextPathNode = _currentPath[_currentPath.Count - 1];
            BoxCollider2D roomCollider = currentRoom.GetComponent <BoxCollider2D>();
            Vector3       roomPosition = currentRoom.transform.position + new Vector3(roomCollider.offset.x, roomCollider.offset.y, 0.0f);

            if (nextPathNode.Position.x - 0.2 < _character.transform.position.x &&
                nextPathNode.Position.x + 0.2 > _character.transform.position.x &&
                CollisionBox.PointInBoxCollision(roomPosition, roomCollider.size, _character.transform.position))
            {
                if (_currentPath.Count > 2)
                {
                    Door currentDoor = (Door)_currentPath[_currentPath.Count - 1].Owner;
                    Door nextDoor    = (Door)_currentPath[_currentPath.Count - 2].Owner;
                    if (currentDoor != null && nextDoor != null && nextDoor.Node.Id == currentDoor.ConnectingDoor.Node.Id)
                    {
                        currentDoor.ActivateEvent(_character);
                    }
                }

                ActivateNextPathNode();
                return(true);
            }

            return(false);
        }