All posts in "Unity3D"

Scaling your Virtual Reality player for fun

Scaling a player in VR opens up a world of options for game design and can be a ton of fun.  In this example, I’ll show you how to quickly adjust the scale of your player, make them shrink and grow at will with a couple lines of c# in your Unity3D project.  We’ll use SteamVR and the CameraRig to make our player tiny, walk through a little door they couldn’t normally get into, then scale them back up on the other side.  Recreate it yourself or download the project sample.

Video

Project Source

Download the project source here: https://unity3dcollege.blob.core.windows.net/site/Magnets/VRScaling.zip

 

Continue reading >
1 Shares

Simple System for Passing Balls in Unity

By Jason Weimann / October 12, 2017

Ball Passing System for Unity

This is a simple system I’ve used to pass soccer balls, hockey pucks, and anything else you can imagine in a sports game from one player to another.  The passing script contains everything needed to make something like this work and the logic for calculating the closest angle to your aim is pretty straightforward (and included in the project source below)

 

Video

Project Download

https://unity3dcollege.blob.core.windows.net/site/Downloads/Passing%20Balls.zip

Continue reading >
2 Shares

Simple Unity3D Snap to Grid System

By Jason Weimann / October 8, 2017

Build your own snap to grid system in minutes with this project as a starting point or sample.  You can create a Unity3D Grid based game easily by creating a single component responsible for giving your project the correct grid coordinates.

This basic grid system works by taking in a vector3 and providing the nearest point on the grid to that position.  Your code only needs to call into the Grid class to get that location, with no other modifications.  The grid can be resized or offset by simply moving it around in the scene, and you can visualize the layout using OnDrawGizmos as seen in the video.

 

Video – Unity3D Grid

Source Code


 

Project Download

https://unity3dcollege.blob.core.windows.net/site/Downloads/Snap%20To%20Grid.zip

 

Continue reading >
6 Shares

Using Delegates in Unity for Coroutine Callbacks

By Jason Weimann / September 22, 2017

C# delegates and events are extremely powerful and understanding them will make your life as a Unity developer much easier.  Luckily, they’re pretty easy to learn and you can start incorporating them in your projects today.  In this 2 part post, I cover the basics of delegates and how they work, then lead into how you can use delegates as callbacks for your coroutines.  With this technique, you can launch a coroutine that can perform whatever action(s) you choose when it’s done, all in a clean and reusable manner.

Part 1 – Delegate Basics (4 mins)

Part 2 – Delegates as Callbacks for Coroutines (4 mins)

Conclusions

Using delegates can make your project clean and extensible, removing the need for endless if statements, switches, etc.

Continue reading >
8 Shares

Unity3D Interfaces vs Abstract Classes

By Jason Weimann / September 11, 2017

If you’re not using Interfaces and Abstract classes in your Unity projects, you’re missing out. These 2 concepts are extremely helpful for c# development, and using them properly can make your game code simple and extensible. In this article, I’ll point out the differences between the two, benefits and drawbacks, and when to use each of them.

Differences

Interface

Abstract Class

GetComponent<T>

Yes

Yes

FindObjectOfType<T>

No

Yes

Define a Contract

Yes

Yes

Default Implementation

No

Yes

Multiple on a Class

Yes

No

Vary Base Class

Yes

No

Video 1 – Interfaces

 

Video 2 – Abstract Classes

Continue reading >
6 Shares

Replace GameObjects or Prefabs with another Prefab

By Jason Weimann / September 7, 2017

Do you have a bunch of gameobjects in your scene that you want to replace with a prefab?  Maybe you’ve been working with a placeholder object while you wait for the art & prefab to be ready?  If so, this simple editor script makes it easy.  Add this script to your Unity3D project in an Editor folder and you can quickly swap out your gameobjects with any prefab with the click of a button.

Note: I’m not sure what the original source for this script was, but I believe it was an adapted / inspired version from the scripts found on the Unity forums.  Definitely want to give credit to the forum posters here: https://forum.unity3d.com/threads/replace-game-object-with-prefab.24311/

Continue reading >
10 Shares

Customizing the Hierarchy – Bold Prefab Text

By Jason Weimann / September 4, 2017

Customize your Scene Hierarchy with a simple editor script.  Make your prefabs bold and bright, easy to recognize.  Or extend this out further and show more detailed info in the scene hierarchy to make your workflow more streamlined.

Video

Code

Conclusions

Remember there are plenty of great editor extensions that add this kind of functionality and a whole lot more on the asset store.  If you’re interested in building your own extension, that’s awesome, but if you just want some cool extra functionality, make sure to check out those extensions as well.

Continue reading >
6 Shares

Basics – How to load a Unity scene after a delay

By Jason Weimann / September 3, 2017

Need to load a Unity scene after a configurable delay?  This video will show you the steps required to do it easily with configurable settings in the inspector.

Video

Project Download

https://unity3dcollege.blob.core.windows.net/site/YT%Downloads/LoadSceneTimed.zip

Conclusions / Alternatives

As I mentioned in the video, you can alternatively use the pattern of StartCoroutine and use a yield return new WaitForSeconds() call to do the delay instead of a timer.  You do lose the ability to debug it in the inspector though, which is why I prefer the timer method.  Either solution will work fine to accomplish the task though.

Continue reading >
1 Shares

Switching Control of a Character between Player & AI in Unity3D

By Jason Weimann / August 30, 2017

Do you want to allow players to take control of any character in your Unity3D game? With the right architecture, it’s not too hard to make this happen. Switch between player controlled and AI control for your characters easily by splitting out the logic and swapping them when you need. A system like this can help with sports games (taking control of a single character at once) or any other situation where you may have an NPC that you want to become player controlled.. think games where your character can charm/control enemies to fight along side them. Swapping out the enemies ‘brain’ is a simple clean solution.

Video

Conclusions

While this is a basic example of the concept, you can take it a lot further in a real game. You can build up state machines, use ScriptableObjects to define your brains, and build up a strong interchangeable system character control.

Continue reading >
6 Shares
Page 2 of 14