Hi! New on c# If some one can help please tag me. Thank you. So how can I make a tile map that works like in the animation below? Its like if the player passes between the walls they show up but if he hits the walls he respawns but remembers where the walls are. Unity
I tried this but didnt worked because I dont know what to put where and what is what in the code exactly just to try out how to switch with space bar:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Tilemaps;
public class Tilehideshow : MonoBehaviour
{
private Tilemap tilemap;
void Start()
{
// u/fixme
tilemap = GameObject.FindWithTag(“Tilemap”).GetComponent<Tilemap>();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
SwitchTiles();
}
}
void SwitchTiles()
{
BoundsInt bounds = tilemap.cellBounds;
bool updated = false;
foreach (Vector3Int pos in bounds.allPositionsWithin)
{
TileBase tile = tilemap.GetTile(pos);
if (tile && tile is SwitchableTile)
{
if (!updated)
{
Sprite sprite = ((SwitchableTile)tile).GetNextSprite();
((SwitchableTile)tile).sprite = sprite;
updated = true;
}
tilemap.RefreshTile(pos);
}
}
}
}
You’re going to need to provide more information to get specific help.
For starters, what engine are you trying to do this in? (eg Unity, MonoGame, etc.)
Additionally you may want to try asking on the subreddit for the specific engine you’re using, or on r/LearnCSharp; just make sure you have specific questions to ask rather than just “How can I do this whole thing”.
I can assume its unity because of the using Unityengine line at the top
Noted. Thank you!
I’d use code.
Hmm intresting 🙂 tell me more.
C# devs
null reference exceptions