Skip to main content
edited body
Source Link
Philipp
  • 123.2k
  • 28
  • 264
  • 345

In order for an object to be detectable by the collision detection system of the engine, it needs a collider component. There are both 2d and 3d colliders that come in different shapes. So you need to pick the one that's most appropriate for the shape of your object and then adjust its dimensions accordingly.

After you added a collider to an object, there are different ways to detect collisions with it:

  • If it's about detecting mouse cursor clicks, then having a script that implements the IPointerClickHandler interface isn't a bad approach. No, it's not obsolete. It was just moved from the engine core to a package, just like the rest of the UI system. You now find it in the documentation for com.unity.ugui.

    In order for it to work, it requires two additional things to be present in your scene:

    1. a Physics RaycasterPhysics Raycaster and/or Physics 2D RaycasterPhysics 2D Raycaster component on your camera (depending on whether you want to detect 3d or 2d colliders).
    2. An Event System component somewhere in the scene.
  • If it's not about mouse cursor clicks (or at least not directly), you can use the Physics class (for 3d colliders) or Physics2D class. They offer several methods to detect all colliders currently overlapping various geometrical shapes.

  • You can mark colliders as triggers. When you do that, then scripts on these objects will receive OnTriggerEnter, OnTriggerExit and OnTriggerStay messages. Note that these will only trigger for objects that have Rigidbody components in addition to a collider.

  • When both colliders have rigidbodies (or when one of them is static), which means that the engine treats them as solid objects, then they will also trigger OnCollisionEnter, OnCollisionExit and OnCollisionStay messages as soon as they get into contact. These messages have the advantage over OnTrigger messages that they contain a lot more information on how exactly the collision occured.

More information in the manual.

In order for an object to be detectable by the collision detection system of the engine, it needs a collider component. There are both 2d and 3d colliders that come in different shapes. So you need to pick the one that's most appropriate for the shape of your object and then adjust its dimensions accordingly.

After you added a collider to an object, there are different ways to detect collisions with it:

  • If it's about detecting mouse cursor clicks, then having a script that implements the IPointerClickHandler interface isn't a bad approach. No, it's not obsolete. It was just moved from the engine core to a package, just like the rest of the UI system. You now find it in the documentation for com.unity.ugui.

    In order for it to work, it requires two additional things to be present in your scene:

    1. a Physics Raycaster and/or Physics 2D Raycaster component on your camera (depending on whether you want to detect 3d or 2d colliders).
    2. An Event System component somewhere in the scene.
  • If it's not about mouse cursor clicks (or at least not directly), you can use the Physics class (for 3d colliders) or Physics2D class. They offer several methods to detect all colliders currently overlapping various geometrical shapes.

  • You can mark colliders as triggers. When you do that, then scripts on these objects will receive OnTriggerEnter, OnTriggerExit and OnTriggerStay messages. Note that these will only trigger for objects that have Rigidbody components in addition to a collider.

  • When both colliders have rigidbodies (or when one of them is static), which means that the engine treats them as solid objects, then they will also trigger OnCollisionEnter, OnCollisionExit and OnCollisionStay messages as soon as they get into contact. These messages have the advantage over OnTrigger messages that they contain a lot more information on how exactly the collision occured.

More information in the manual.

In order for an object to be detectable by the collision detection system of the engine, it needs a collider component. There are both 2d and 3d colliders that come in different shapes. So you need to pick the one that's most appropriate for the shape of your object and then adjust its dimensions accordingly.

After you added a collider to an object, there are different ways to detect collisions with it:

  • If it's about detecting mouse cursor clicks, then having a script that implements the IPointerClickHandler interface isn't a bad approach. No, it's not obsolete. It was just moved from the engine core to a package, just like the rest of the UI system. You now find it in the documentation for com.unity.ugui.

    In order for it to work, it requires two additional things to be present in your scene:

    1. a Physics Raycaster and/or Physics 2D Raycaster component on your camera (depending on whether you want to detect 3d or 2d colliders).
    2. An Event System component somewhere in the scene.
  • If it's not about mouse cursor clicks (or at least not directly), you can use the Physics class (for 3d colliders) or Physics2D class. They offer several methods to detect all colliders currently overlapping various geometrical shapes.

  • You can mark colliders as triggers. When you do that, then scripts on these objects will receive OnTriggerEnter, OnTriggerExit and OnTriggerStay messages. Note that these will only trigger for objects that have Rigidbody components in addition to a collider.

  • When both colliders have rigidbodies (or when one of them is static), which means that the engine treats them as solid objects, then they will also trigger OnCollisionEnter, OnCollisionExit and OnCollisionStay messages as soon as they get into contact. These messages have the advantage over OnTrigger messages that they contain a lot more information on how exactly the collision occured.

More information in the manual.

added 33 characters in body
Source Link
Philipp
  • 123.2k
  • 28
  • 264
  • 345

In order for an object to be detectable by the collision detection system of the engine, it needs a collider component. There are both 2d and 3d colliders that come in different shapes. So you need to pick the one that's most appropriate for the shape of your object and then adjust its dimensions accordingly.

After you added a collider to an object, there are different ways to detect collisions with it:

  • If it's about detecting mouse cursor clicks, then having a script that implements the IPointerClickHandler interface isn't a bad approach. No, it's not obsolete. It was just moved from the engine core to a package, just like the rest of the UI system. You now find it in the documentation for com.unity.ugui.

    Remember that you need an EventSystem component somewhere in the sceneIn order for these interfaces to do anything. It is easyit to forget that this is necessarywork, because you are going to get one automatically as soon as you add a UI canvasit requires two additional things to the game. But ifbe present in your game doesn't have an UI (yet), or if you are using a different UI system (like UI Elements) then it's easy to forget about this and get confused why the OnPointer* methods don't get called.scene:

    1. a Physics Raycaster and/or Physics 2D Raycaster component on your camera (depending on whether you want to detect 3d or 2d colliders).
    2. An Event System component somewhere in the scene.
  • If it's not about mouse cursor clicks (or at least not directly), you can use the Physics class (for 3d colliders) or Physics2D class. They offer several methods to detect all colliders currently overlapping various geometrical shapes.

  • You can mark colliders as triggers. When you do that, then scripts on these objects will receive OnTriggerEnter, OnTriggerExit and OnTriggerStay messages. Note that these will only trigger for objects that have Rigidbody components in addition to a collider.

  • When both colliders have rigidbodies (or when one of them is static), which means that the engine treats them as solid objects, then they will also trigger OnCollisionEnter, OnCollisionExit and OnCollisionStay messages as soon as they get into contact. These messages have the advantage over OnTrigger messages that they contain a lot more information on how exactly the collision occured.

More information in the manual.

In order for an object to be detectable by the collision detection system of the engine, it needs a collider component. There are both 2d and 3d colliders that come in different shapes. So you need to pick the one that's most appropriate for the shape of your object and then adjust its dimensions accordingly.

After you added a collider to an object, there are different ways to detect collisions with it:

  • If it's about detecting mouse cursor clicks, then having a script that implements the IPointerClickHandler interface isn't a bad approach. No, it's not obsolete. It was just moved from the engine core to a package, just like the rest of the UI system. You now find it in the documentation for com.unity.ugui.

    Remember that you need an EventSystem component somewhere in the scene for these interfaces to do anything. It is easy to forget that this is necessary, because you are going to get one automatically as soon as you add a UI canvas to the game. But if your game doesn't have an UI (yet), or if you are using a different UI system (like UI Elements) then it's easy to forget about this and get confused why the OnPointer* methods don't get called.

  • If it's not about mouse cursor clicks (or at least not directly), you can use the Physics class (for 3d colliders) or Physics2D class. They offer several methods to detect all colliders currently overlapping various geometrical shapes.

  • You can mark colliders as triggers. When you do that, then scripts on these objects will receive OnTriggerEnter, OnTriggerExit and OnTriggerStay messages. Note that these will only trigger for objects that have Rigidbody components in addition to a collider.

  • When both colliders have rigidbodies (or when one of them is static), which means that the engine treats them as solid objects, then they will also trigger OnCollisionEnter, OnCollisionExit and OnCollisionStay messages as soon as they get into contact. These messages have the advantage over OnTrigger messages that they contain a lot more information on how exactly the collision occured.

More information in the manual.

In order for an object to be detectable by the collision detection system of the engine, it needs a collider component. There are both 2d and 3d colliders that come in different shapes. So you need to pick the one that's most appropriate for the shape of your object and then adjust its dimensions accordingly.

After you added a collider to an object, there are different ways to detect collisions with it:

  • If it's about detecting mouse cursor clicks, then having a script that implements the IPointerClickHandler interface isn't a bad approach. No, it's not obsolete. It was just moved from the engine core to a package, just like the rest of the UI system. You now find it in the documentation for com.unity.ugui.

    In order for it to work, it requires two additional things to be present in your scene:

    1. a Physics Raycaster and/or Physics 2D Raycaster component on your camera (depending on whether you want to detect 3d or 2d colliders).
    2. An Event System component somewhere in the scene.
  • If it's not about mouse cursor clicks (or at least not directly), you can use the Physics class (for 3d colliders) or Physics2D class. They offer several methods to detect all colliders currently overlapping various geometrical shapes.

  • You can mark colliders as triggers. When you do that, then scripts on these objects will receive OnTriggerEnter, OnTriggerExit and OnTriggerStay messages. Note that these will only trigger for objects that have Rigidbody components in addition to a collider.

  • When both colliders have rigidbodies (or when one of them is static), which means that the engine treats them as solid objects, then they will also trigger OnCollisionEnter, OnCollisionExit and OnCollisionStay messages as soon as they get into contact. These messages have the advantage over OnTrigger messages that they contain a lot more information on how exactly the collision occured.

More information in the manual.

added 331 characters in body
Source Link
Philipp
  • 123.2k
  • 28
  • 264
  • 345

In order for an object to be detectable by the collision detection system of the engine, it needs a collider component. There are both 2d and 3d colliders that come in different shapes. So you need to pick the one that's most appropriate for the shape of your object and then adjust its dimensions accordingly.

After you added a collider to an object, there are different ways to detect collisions with it:

  • If it's about detecting mouse cursor clicks, then having a script that implements the IPointerClickHandler interface isn't a bad approach. No, it's not obsolete. It was just moved from the engine core to a package, just like the rest of the UI system. You now find it in the documentation for com.unity.ugui. Remember that you need an EventSystem component somewhere in the scene for these interfaces to do anything.

    If it's about detecting mouse cursor clicks, then having a script that implements the IPointerClickHandler interface isn't a bad approach. No, it's not obsolete. It was just moved from the engine core to a package, just like the rest of the UI system. You now find it in the documentation for com.unity.ugui.

    Remember that you need an EventSystem component somewhere in the scene for these interfaces to do anything. It is easy to forget that this is necessary, because you are going to get one automatically as soon as you add a UI canvas to the game. But if your game doesn't have an UI (yet), or if you are using a different UI system (like UI Elements) then it's easy to forget about this and get confused why the OnPointer* methods don't get called.

  • If it's not about mouse cursor clicks (or at least not directly), you can use the Physics class (for 3d colliders) or Physics2D class. They offer several methods to detect all colliders currently overlapping various geometrical shapes.

    If it's not about mouse cursor clicks (or at least not directly), you can use the Physics class (for 3d colliders) or Physics2D class. They offer several methods to detect all colliders currently overlapping various geometrical shapes.

  • You can mark colliders as triggers. When you do that, then scripts on these objects will receive OnTriggerEnter, OnTriggerExit and OnTriggerStay messages. Note that these will only trigger for objects that have Rigidbody components in addition to a collider.

    You can mark colliders as triggers. When you do that, then scripts on these objects will receive OnTriggerEnter, OnTriggerExit and OnTriggerStay messages. Note that these will only trigger for objects that have Rigidbody components in addition to a collider.

  • When both colliders have rigidbodies (or when one of them is static), which means that the engine treats them as solid objects, then they will also trigger OnCollisionEnter, OnCollisionExit and OnCollisionStay messages as soon as they get into contact. These messages have the advantage over OnTrigger messages that they contain a lot more information on how exactly the collision occured.

    When both colliders have rigidbodies (or when one of them is static), which means that the engine treats them as solid objects, then they will also trigger OnCollisionEnter, OnCollisionExit and OnCollisionStay messages as soon as they get into contact. These messages have the advantage over OnTrigger messages that they contain a lot more information on how exactly the collision occured.

More information in the manual.

In order for an object to be detectable by the collision detection system of the engine, it needs a collider component. There are both 2d and 3d colliders that come in different shapes. So you need to pick the one that's most appropriate for the shape of your object and then adjust its dimensions accordingly.

After you added a collider to an object, there are different ways to detect collisions with it:

  • If it's about detecting mouse cursor clicks, then having a script that implements the IPointerClickHandler interface isn't a bad approach. No, it's not obsolete. It was just moved from the engine core to a package, just like the rest of the UI system. You now find it in the documentation for com.unity.ugui. Remember that you need an EventSystem component somewhere in the scene for these interfaces to do anything.
  • If it's not about mouse cursor clicks (or at least not directly), you can use the Physics class (for 3d colliders) or Physics2D class. They offer several methods to detect all colliders currently overlapping various geometrical shapes.
  • You can mark colliders as triggers. When you do that, then scripts on these objects will receive OnTriggerEnter, OnTriggerExit and OnTriggerStay messages. Note that these will only trigger for objects that have Rigidbody components in addition to a collider.
  • When both colliders have rigidbodies (or when one of them is static), which means that the engine treats them as solid objects, then they will also trigger OnCollisionEnter, OnCollisionExit and OnCollisionStay messages as soon as they get into contact. These messages have the advantage over OnTrigger messages that they contain a lot more information on how exactly the collision occured.

More information in the manual.

In order for an object to be detectable by the collision detection system of the engine, it needs a collider component. There are both 2d and 3d colliders that come in different shapes. So you need to pick the one that's most appropriate for the shape of your object and then adjust its dimensions accordingly.

After you added a collider to an object, there are different ways to detect collisions with it:

  • If it's about detecting mouse cursor clicks, then having a script that implements the IPointerClickHandler interface isn't a bad approach. No, it's not obsolete. It was just moved from the engine core to a package, just like the rest of the UI system. You now find it in the documentation for com.unity.ugui.

    Remember that you need an EventSystem component somewhere in the scene for these interfaces to do anything. It is easy to forget that this is necessary, because you are going to get one automatically as soon as you add a UI canvas to the game. But if your game doesn't have an UI (yet), or if you are using a different UI system (like UI Elements) then it's easy to forget about this and get confused why the OnPointer* methods don't get called.

  • If it's not about mouse cursor clicks (or at least not directly), you can use the Physics class (for 3d colliders) or Physics2D class. They offer several methods to detect all colliders currently overlapping various geometrical shapes.

  • You can mark colliders as triggers. When you do that, then scripts on these objects will receive OnTriggerEnter, OnTriggerExit and OnTriggerStay messages. Note that these will only trigger for objects that have Rigidbody components in addition to a collider.

  • When both colliders have rigidbodies (or when one of them is static), which means that the engine treats them as solid objects, then they will also trigger OnCollisionEnter, OnCollisionExit and OnCollisionStay messages as soon as they get into contact. These messages have the advantage over OnTrigger messages that they contain a lot more information on how exactly the collision occured.

More information in the manual.

Source Link
Philipp
  • 123.2k
  • 28
  • 264
  • 345
Loading