1. Hey how's it going I have recently taken up C# and would enjoy making some plugins, however I have hit a small speed bump - trying to create a simple sphere and trigger.

    OnTriggerEnter won't trigger in this script:

    Code:
            class CreateASphere : MonoBehaviour
            {            private BaseEntity theSphere;
                private GameObject theGameObject;
               
                public static void CreateTheSphere(Vector3 XYZCoordinates)
                {
                    BaseEntity theSphere = new BaseEntity(); // Create new BaseEntity                                                                                      theSphere = GameManager.server.CreateEntity("assets/prefabs/visualization/sphere.prefab", XYZCoordinates, new Quaternion(0, 0, 0, 0), true);
                    theSphere.Spawn();                var theSpheresRigidBody = theSphere.gameObject.AddComponent<Rigidbody>();
                    // variable ^^ becomes --->>>
                    theSpheresRigidBody.useGravity = false;
                    theSpheresRigidBody.isKinematic = true;
                    theSpheresRigidBody.detectCollisions = true;                               var theSpheresBoxCollider = theSphere.gameObject.AddComponent<BoxCollider>();
                    theSpheresBoxCollider.isTrigger = true;
                    theSpheresBoxCollider.enabled = true;
                    //theSpheresBoxCollider.size = new Vector3(1, 2, 1);            }            public void OnTriggerEnter(Collider newCollider)
                {
                    var thePlayer = newCollider.GetComponentInParent<BasePlayer>();                if (thePlayer != null)
                    {
                     theSphere.Kill();
                    }                          }
    }
    I am aware the collider requires a rigidbody as well as being kinematic - can anyone please point me in the right direction what I am doing incorrectly or provide some guidance? it would be highly appreciated
     
  2. Wulf

    Wulf Community Admin

    I don't think you can have hooks inside of other classes like that.

    Edit: Ignore that, noticed it isn't a hook.
     
  3. Try add this this after declare BoxCollider
    Code:
    TriggerBase trigger = theSpheresBoxCollider.GetComponent<TriggerBase>() ?? theSpheresBoxCollider.gameObject.AddComponent<TriggerBase>();
    trigger.interestLayers = LayerMask.GetMask("Player (Server)");
    trigger.enabled = true;