Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity3d do something when attached a script to gameobject

My problem is, when I attached my script to a game object, I want to make some calculation and add Edge Collider to this game object. Is there any event like "OnAttached" or something else?

Thanks for all your helps.

Thanks to Ruben I found the solution. RequireComponent is what I was looking for, but I actually needed an event like "OnAttached" and at last I found. It is "void Reset()".

like image 958
Cenkisabi Avatar asked Aug 03 '26 22:08

Cenkisabi


1 Answers

The automated addition of the Edge Collider can be done by using [RequireComponent(typeof(EdgeCollider))]

Learn more here: https://docs.unity3d.com/ScriptReference/RequireComponent.html

Edit: OP says this wasn't helpful, refer to his comment below for more information:

You then can simply put all necessary calculations into the Start() functions, which get called, when a script is enabled.

https://docs.unity3d.com/ScriptReference/MonoBehaviour.Start.html

like image 52
Ruben Bohnet Avatar answered Aug 06 '26 10:08

Ruben Bohnet