[Unity3d] using a collision body as a trigger for simple automatic door opening

Source: Internet
Author: User

A classic tutorial Translated From DT: Introduction to unity.


Trigger usage in game production is very convenient and practical. This document briefly introduces how to use a simple trigger to automatically open and close the door.

First, make sure that you have set the animation for the door.

The specific process is as follows.

Choose WINDOW> animation to open the animation window. Select the animation door to be added and click the red button to create a new animation.

After selecting an animation element (such as postion. X), click the Add key frame button:

Drag the timeline and let go at the animation end point:

Drag the door to the position you want to stop in the scene to create the key frame of the animation end point:

Click the keys on the animation panel to preview the door start effect.

At this point, a simple animation is completed.

The next step is to create a trigger.

First, add a gameobject-> creaateother-> sphere object, and use it as a trigger.

After creation, remove the selected meshrender to make the sphere transparent:

Add a built-in unity script to this sphere to enable the trigger function:

Select the target object of the trigger:

Set the active event to animate:

However, at this time, the sphere is a collision body and cannot be rushed into to implement the trigger function. Therefore, you need to check the is trigger option:

When we run it again, we will find that the door will automatically open when we approach it.

The source code of the project is too large to be uploaded. You can send me an email if necessary.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.