How can my character be destroyed upon contact with 1 specific object?

Hi, i this is my first day with Unity and i am trying to build a little game (you have to steer between a lot of cubes). Right now nothing happens when i hit the cubes, but i want it so my character get’s destroyed when i hit these cubes. How can i do this?

You can use OnCollisionEnter, assuming your player and the cubes have Colliders and at least one has a non-kinematic RigidBody attached. Assuming your Cubes had say a “Cube” behavior attached to each of them, this may work (untested):

void OnCollisionEnter(Collision collision)
	{
		if(collision.gameObject.GetComponent<Cube>())
		{
			Destroy(this);
            // Or do something that means "destroyed" in your game.
		}
	}

Edit: You’re probably using a CharacterController for your player, yes? In which case you can use (untested):

void OnControllerColliderHit(ControllerColliderHit hit)
	{
		if(hit.gameObject.GetComponent<Cube>())
		{
			Destroy(this);
            // Or whatever you wanna do
		}
	}