Hello! I’m rather new to game development and I’m having trouble making an object disappear when the player touches it.
You can see the code for the script here:
using UnityEngine;
using System.Collections;
public class collect : MonoBehaviour {
void Update ()
{
}
void OnCollisionEnter(Collision col)
{
if(col.gameObject.name == "platform")
{
Destroy(gameObject);
Debug.Log("collision detected!");
}
}
}
The object being destroyed is called “platform” because it was originally being used as a platform in-game. You can view its inspector here:
Why won’t this code work?
Thanks in advance!