Open in app

Sign In

Write

Sign In

Richard Morgan
Richard Morgan

26 Followers

Home

About

Feb 11

Spawning AI Objects in Unity

We want to spawn a bunch of AI objects in Unity. Here’s what it will look like: In this example, every time the X key is pressed, a new AI object is created and spawned, complete with Nav Mesh Agent instructions. We’ve already got our Navigation system and our…

Made With Unity

3 min read

Spawning AI Objects in Unity
Spawning AI Objects in Unity
Made With Unity

3 min read


Jan 29

Serialized Custom Classes in Unity

Let’s say we need an array of things for our game. Things could be items, or characters, etc.. …

Gamedevhq

2 min read

Serialized Custom Classes in Unity
Serialized Custom Classes in Unity
Gamedevhq

2 min read


Jan 10

Using Singletons in Unity

A singleton is a special class that can only have one instance. Because of this, it’s super-easy to reference functions inside a singleton from another class. Singletons can talk to other singletons, and non-singleton classes can talk to singletons, but singletons can not talk to non-singleton classes. Here’s an example were we use singletons to send debug messages, change a text box, and instantiate a prefab:

Made With Unity

2 min read

Using Singletons in Unity
Using Singletons in Unity
Made With Unity

2 min read


Jan 9

Generating Offmesh Links Unity AI

Let’s add a new waypoint to our map and have our ai jump to it like this: On the Object section of the Navigation tab we need to activate Navigation Static and Generate OffMeshLinks:

Gamedevhq

1 min read

Generating Offmesh Links Unity AI
Generating Offmesh Links Unity AI
Gamedevhq

1 min read


Jan 9

FSM in Unity to Create Smart AI

Ok, let’s build a Finite State Machine that will act as our smart AI. As our AI travels the waypoints, we want it to go into attack mode at each point. For now we’ll just have it stop for 3 seconds and then move on to the next waypoint. Like this: All we need is an If statement in our Attack Switch Case that calls a coroutine and updates the switch:

Gamedevhq

2 min read

FSM in Unity to Create Smart AI
FSM in Unity to Create Smart AI
Gamedevhq

2 min read


Jan 8

Unity — changing material with enums

Let’s take our previous example a step further… Suppose we want to change the color of our ai to match the change in speed when we press the space bar, like this: Since we’ve already set up our custom class, we can easily add a material to our enum:

Gamedevhq

1 min read

Unity — changing material with enums
Unity — changing material with enums
Gamedevhq

1 min read


Jan 8

Unity — custom class enums for fun and profit

Let’s have some fun with enums using a custom class. We’ll make 3 speeds for our ai and cycle through the speeds every time we press the space bar, like this: First, we create our new custom class, AISpeed: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.AI; [System.Serializable] public class AISpeed {…

Gamedevhq

4 min read

Unity — custom class enums for fun and profit
Unity — custom class enums for fun and profit
Gamedevhq

4 min read


Jan 7

Unity — Moving Agents on Navmesh

Let’s add an Agent to our Navmesh and have it loop through a series of waypoints like this: For our Agent, let’s add a sphere to the scene, and add a Nav Mesh Agent component to the sphere. For our waypoints, let’s add some cubes with Box Collider components. Next…

Gamedevhq

2 min read

Unity — Moving Agents on Navmesh
Unity — Moving Agents on Navmesh
Gamedevhq

2 min read


Jan 7

Setting up Navmesh in Unity

If we want to build an AI agent that can travel around a scene autonomously, we need a way to set the area and boundaries. We do this in Unity using a Navmesh: Turn on the Navigation tab using the menu Windows — AI:

Gamedevhq

1 min read

Setting up Navmesh in Unity
Setting up Navmesh in Unity
Gamedevhq

1 min read


Jan 5

Click to Move System in Unity

Let’s write a simple script that will move an object to a clicked location like this: Here’s the script that gets added to the player object: using System.Collections; using System.Collections.Generic; using UnityEngine; public class ClickToMove : MonoBehaviour { // Variable to store the speed at which the object should move…

Gamedevhq

3 min read

Click to Move System in Unity
Click to Move System in Unity
Gamedevhq

3 min read

Richard Morgan

Richard Morgan

26 Followers

Unity and Flutter developer interested in creating mixed-reality applications.

Following
  • Dennisse Pagán Dávila

    Dennisse Pagán Dávila

  • Jared Amlin

    Jared Amlin

  • Chris Hilton

    Chris Hilton

  • Chinyere Akanno

    Chinyere Akanno

  • Frank Warman

    Frank Warman

See all (31)

Help

Status

Writers

Blog

Careers

Privacy

Terms

About

Text to speech