- Home /
Question by
WhatisitStudios · May 26 at 07:17 PM ·
collisiontilemapprocedural generation
Colliders not Working with Tilemap Generation!
Hey, making some random tilemap generation, but tilemap colliders aren't working! Help! Here's the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Tilemaps;
public class ProceduralGeneration : MonoBehaviour
{
[SerializeField] int width;
[SerializeField] int minStoneHeight, maxStoneHeight;
//[SerializeField] GameObject dirt, grass, stone;
[SerializeField] Tilemap dirtTilemap, grassTilemap, stoneTilemap;
[SerializeField] Tile dirt, grass, stone;
[Range(0, 200)]
[SerializeField] float heightValue, smoothness;
void Start()
{
this.transform.position = new Vector3(width * -1, -10, 0);
Generation();
}
void Generation()
{
for (int x = 0; x < width; x++)
{
int height = Mathf.RoundToInt(heightValue * Mathf.PerlinNoise(x / smoothness, 0));
int minStoneSpawnDistance = height - minStoneHeight;
int maxStoneSpawnDistance = height - maxStoneHeight;
int totalStoneSpawnDistance = Random.Range(minStoneSpawnDistance, maxStoneSpawnDistance);
for (int y = 0; y < height; y++)
{
if (y < totalStoneSpawnDistance)
{
//SpawnObject(stone, x, y);
stoneTilemap.SetTile(new Vector3Int(x, y, 0), stone);
}
else
{
//SpawnObject(dirt, x, y);
stoneTilemap.SetTile(new Vector3Int(x, y, 0), dirt);
}
}
//SpawnObject(grass, x, height);
stoneTilemap.SetTile(new Vector3Int(x, height, 0), grass);
}
}
}
Any help would be appreciated.
Comment
Your answer
Follow this Question
Related Questions
Modular Room System Similar to Mega Man 0 Answers
Best way to make a big 2D map as smooth as possible? 1 Answer
Collision mesh won't form until mesh is moved? 2 Answers
Sprite collision with Tilemap 2 Answers