예제 #1
0
    private void TeleportIfPossible()
    {
        CollisionMap      collisionMap    = Game.instance.levelGenerator.collisionMap;
        List <Vector2Int> viablePositions = collisionMap.EmptyPositionsNearPosition(mTeleportTarget, 1);

        if (viablePositions.Count == 0)
        {
            return;
        }

        Vector2Int newTarget = viablePositions.Find(i => (i.x == mTeleportTarget.x && i.y == mTeleportTarget.y + 1));

        if (newTarget.x != 0 || newTarget.y != 0)
        {
            mTeleportTarget = newTarget;
        }
        else
        {
            mTeleportTarget = viablePositions[0];
        }

        Vector2Int currentPos = MapCoordinateHelper.WorldToMapCoords(transform.position);

        if (!collisionMap.RemoveMarking(commonComponents.simpleMovement.uniqueCollisionIdentity))
        {
            Debug.LogError("CM error in PlayerController");
        }

        collisionMap.MarkSpace(mTeleportTarget.x, mTeleportTarget.y, commonComponents.simpleMovement.uniqueCollisionIdentity);

        Game.instance.avatar.transform.position          = MapCoordinateHelper.MapToWorldCoords(mTeleportTarget);
        Game.instance.avatar.follower.transform.position = Game.instance.avatar.transform.position + new Vector3(-0.25f, 0f, 0.25f);

        GameObject effect = PrefabManager.instance.InstantiatePrefabByName("CFX2_WWExplosion_C");

        effect.transform.position = Game.instance.avatar.transform.position;
        effect.AddComponent <DestroyAfterTimeElapsed>().time = 2f;
    }