The use of triggers in game making is very convenient and very practical. This is a brief introduction to how to use a simple trigger to achieve the automatic door closing effect.
First make sure that you have animated settings on the door.
The specific process is as follows.
Select Window->animation to open the Animation window, select the door where you want to add the animation, and click the Red button to create a new animation.
After selecting a feature that needs to be animated (such as Postion.x), click the Add keyframe button:
Drag the timeline to let go at the end of the animation:
In the scene, drag the door to where you want to stop, creating keyframes for the end of the animation:
Click the Play button on the animation panel to preview the effect of the door.
At this point, the simple animation even finished the production.
The next step is making the trigger.
First, add a Gameobject->creaateother->sphere spherical object and use it as a trigger.
Once created, remove the checked meshrender to make the sphere transparent:
Add a unity-brought script to the sphere to make it function as a trigger:
Select the target object for the trigger:
Set its active event to animate:
However, this time the sphere is a collision body, can not be rushed into the implementation of the trigger function, so you need to check the IS trigger option:
Run again this time and you will find that the door will open automatically as we approach it.
Unity3d using collision body as trigger to realize simple automatic door opening