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. Required fields are marked *

You May Also Like

Cyber Security

In this article, we are going to examine real-world logic bombs. Also, we are going to create one with Python for seeing how to...

Cyber Security

Welcome to the second tutorial on networks for hackers. We are going to learn network types and weaknesses and strengths of networks in this...

Programming

In this tutorial, we going to learn file handling with Python. At the end of the article, you will be ready to work with...

Cyber Security

In this article, we going to learn how networking works and simple terms in networking. Also, we are going to learn simple network attacks....