(new to unity) i have sound code for deleting game objects but it says there is compiling errors

Please use code tags for the code. If you click on any other thread with some code in it, you will see that it renders properly, while yours does not.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace collisiontrigger
{
  public class collisiontrigger : MonoBehaviour
  {
    // Start is called before the first frame update
    void OnTriggerEnter(Collider other)
    {
      if (other.gameObject.CompareTag("enemy bean"))
      {
        Destroy(gameObject);
      }
    }
  }
}

I initially wrongly assumed you had one brace too many, but that’s not the case.
What is the message of the error you’re getting? It could be that your class name cannot be the same as the namespace, but I can’t tell from the top of my head.

If you’re a beginner, you don’t really need namespaces.
Do this instead.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CollisionTrigger : MonoBehaviour
{
  // Start is called before the first frame update
  void OnTriggerEnter(Collider other)
  {
    if (other.gameObject.CompareTag("enemy bean"))
    {
      Destroy(gameObject);
    }
  }
}
1 Like