- Home /
How can I write my own collider in Unity
I want to write a custom collider in unity because i want to implement some specific behaviors for colliders to work with. Is there any way to implement that.
By behaviours I mean that when some trigger or mouseover or any such event is encountered, the collider should return some values and do some specified tasks. fafase, thanks for your help. I will try that
Answer by whydoidoit · Feb 26, 2014 at 06:58 AM
What kind of behaviours are you talking about?
You can make any shape of collider using a MeshCollider. You can customise what happens when things collide using OnCollisionEnter and physics processing.
Tried to turn the OP's answer-comment into a comment and everything got blasted into one giant comment. So I'm not sure if this started life as an answer. But:
Yes, with normal colliders you are supposed to have them do specific things. Turning the same color as a ball that hit you (or diff color, or grow... ) is already built into normal colliders.
Answer by fafase · Feb 26, 2014 at 07:02 AM
You should be able to use extension methods on the Collider class if you want to extend your collider. That would allow you to use the engine and your methods.
Creating your own collider, you lose all of the efficient advantages of using Unity.
to create an extension method simply use:
public static UtilityClass{
public static void ExtendCollider(this Collider col){
// use col to access the collider
// You can add any parameters AFTER the Collider param
}
}
then you use it like this:
collider.ExtendCollider();
you do not pass any parameter, the this parameter of the method will point at the instance that is calling the method.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Getting 2 colliders, prefab and clone need help please. 0 Answers
Collision problems? 1 Answer
Collision between two sphere game object 1 Answer
Trigger enter in single direction ??? 3 Answers