I need help. I don’t know how to script. And i have a red square under my map so whenever a player falls they touch the lava and die. Also the game is 2D. I don’t know how to script or code. Please help i need to make this game better. I tried searching: Unity how to change a value when you do a collision. I couldn’t find anything.
Any simple Unity tutorial would have covered colliders, for sure. They are very easy to use, and not hard to code at all. Here’s how you would do it:
Add a collider component to your lava square, that covers the entire area. It could be a box collider 2d or a polygon collider (if the sprite is more complicated). Then, set the collider to Is Trigger. This will allow the player to fall through the collider, whilst still detecting a collision.
Finally, add a script to the lava object that looks something like this:
public class Lava : MonoBehaviour
{
// Called whenever an object passes through the collider
void OnTriggerEnter2D(Collision2D collider)
{
// Destroys the player object if it enters the collider
Destroy(collider.gameObject);
}
}
If you have any questions, please see the docs or see a simple tutorial, for example this one: Collisions in Unity