Connect with us

Hi, what are you looking for?

Unity Trigger System
Unity Trigger System

Game Development

Unity Trigger System

In this tutorial, I going to show you the trigger system in unity. Used frequently in games. we will start from basic afterward we going to look at complex trigger systems.

What Is Trigger System?

The trigger system is basically, can be thought of as the system that monitors the condition required for an event to occur. For example, we have an object and we want to run a command line when that object touches a trigger or exits for this we can use a trigger.

Trigger Syntax

Trigger syntax is so simple but The preparation process of the object can be a bit complicated. Now we going to just look at trigger syntax after that we going to use trigger syntax in the project.

Trigger Example Script

Trigger syntax is so basic, so It is very easy to use. Now, we going to create a trigger system after that we going to examine these functions.

How To Work Trigger System?

Basically, there are 3 types of triggers these OnTriggerEnter, OnTriggerExit, OnTriggerStay.

OnTriggerEnter -> The trigger is triggered as soon as the object hits the trigger.

OnTriggerExit -> Triggered when the object leaves the trigger.

OnTriggerStay -> The trigger is triggered as long as the object remains in the trigger.

Working Multiple Trigger System

Sometimes, we need to use all trigger systems so, let’s create a new script with all triggers. After that, we going to learn how to create a trigger object.

How To Create Trigger Object

We need to trigger an object to use the trigger system so let’s create a new trigger object.

Component List

You should add a rigid body to the game object after that enable the “is trigger” feature of the collider.

Creating A Sample Attack System With Trigger System

Now, we know about the trigger system so we going to create a simple attack system in unity. Create a trigger object and a normal object after that, we going to ready to writing the script.

the script is ready, now, you should add a player, after adding, you should select tag name but before let’s talk about tags.

What is Tag?

Tags are short texts used to introduce an object. For example, unity has 6 tags, if you want to create a new tag, firstly, click on an object and open the tag menu from the top after that, just click for add tag from the bottom of the menu. You can create a new tag from the Tags & Layers menu.

CONGRATULATIONS, YOU COMPLETED TRIGGER SYSTEM IN UNITY!
1 Comment

1 Comment

  1. elijahhertz

    February 17, 2021 at 04:16

    Hi, its pleasant piece of writing regarding media
    print, we all understand media is a wonderful source of facts.

Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like

Programming

clean code is essential for updating scripts, adding new features to code, etc. So every developer, must learn how to clean the code. With...

Daily News

Cloud computing is a system that is often heard today and that most developers use at least once. In this article, we’ll look at...

Game Development

Visual Studio Code without a doubt, most popular and loved code editor in the code editor market. Many developers love working with Vs Code....

Daily News

GitHub Copilot was introduced last year and continues to make it easier for developers with nice updates to date. Although most people see Github...