How to generate tiles for ZigZag-like game?
Hi,
Im Beginner in unity. I want create Tile map according image.
Why the tiles are in wrong way?
It depends on what?
Best Regards
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TileManager : MonoBehaviour
{
public GameObject leftTilePrefab;
public GameObject CurrentTile;
void Start ()
{
for( int i=0 ; i<3 ; i++ )
{
Vector3 pos = CurrentTile.transform.GetChild(0).transform.GetChild(0).position;
CurrentTile = GameObject.Instantiate( leftTilePrefab , pos , Quaternion.identity );
}
}
}
question1.jpg
(147.1 kB)
Comment
Answer by andrew-lukasik · Aug 03, 2021 at 08:49 AM
using UnityEngine;
public class TileManager : MonoBehaviour
{
[SerializeField] GameObject _tilePrefab;
[SerializeField] int numTiles = 100;
[SerializeField] Vector3[] _randomSteps = new Vector3[]{
new Vector3(1,0,0) ,
new Vector3(-1,0,0) ,
new Vector3(0,0,1) , new Vector3(0,0,1) , new Vector3(0,0,1)
};
void Start ()
{
Vector3 pos = transform.position;
for( int i=0 ; i<numTiles ; i++ )
{
GameObject instance = GameObject.Instantiate( _tilePrefab , pos , Quaternion.identity );
pos = pos + _randomSteps[ Random.Range(0,_randomSteps.Length) ];
}
}
}
Your answer
Follow this Question
Related Questions
Draw a line on a texture 0 Answers
Character goes back to a set rotation every time I stop moving. 0 Answers
2D topdown pathfinding ,2D top down path finder 0 Answers
Get adjacent objects (tiles) using Colliders? 0 Answers
Why are the 2D colliders not working? 0 Answers