Connect with us

Hi, what are you looking for?

Game Development

Unity Trigger System

Unity Trigger System
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.

You May Also Like

News

What is LaMDA? The LaMDA is an AI (neural network) developed to realize natural conversations with humans by extracting information from a large amount...

Programming

In this article, we will create a simple timer app for beginners with Swift and SwiftUI. Step 1: Create a Header First, we will...

Programming

Swift optionals can be a bit confusing, in this article we’ll go into detail about optionals. We will look at how they can be...

News

According to a study from Dartmouth College, Dartmouth’s Tuck School of Business, and Indiana University, artificial intelligence systems can be trained to produce human-like...