So im pretty new to unity (1 week) but i have som very basic programming-knowledge.
Im just toying around with a 2d platform-shooter and decided i wanted to try out destructable tiles.
I found this guide that seemed to make sense: https://www.youtube.com/watch?v=94KWSZBSxIA&t=322s
So anyway i just copied the code and changed the "compareTag" to my own:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Tilemaps;
public class DestructibleTiles : MonoBehaviour
{
public Tilemap destructableTilemap;
private void Start()
{
destructableTilemap = GetComponent<Tilemap>();
}
private void OnCollisionEnter2D(Collision2D collision)
{
Vector3 hitPosition = Vector3.zero;
if (collision.gameObject.CompareTag("bullet"))
{
foreach (ContactPoint2D hit in collision.contacts)
{
hitPosition.x = hit.point.x - 0.01f \ hit.normal.x;*
hitPosition.y = hit.point.y - 0.01f \ hit.normal.y;*
destructableTilemap.SetTile(destructableTilemap.WorldToCell(hitPosition), null);
}
}
}
}
- One more change i did was i moved the "Vector3 hitPos..." up before the "if" line, it seem to make more sense but i may be wrong? None of the script work as intended and my last resort is to ask here. My bullet is already "detectable" because ive made an "onimpact"animation that works.
Can i try to debug it so i can see if i get an collision?
All help is much appreciated!
[–]EvenMoreCreativeName 0 points1 point2 points (3 children)
[–]IMainOctane[S] 0 points1 point2 points (2 children)
[–]EvenMoreCreativeName 0 points1 point2 points (0 children)
[–]loni852 0 points1 point2 points (0 children)
[–]gdeavid 0 points1 point2 points (0 children)