Let’s create an Elevator in Unity

Part 1 — Press the button and change color

In this article we will change the color of the elevator button when the player presses it.

Split up functionality for easier and faster development

We want various functions for our elevator. We want a pressable button that changes color, a requirement of enough collectables collected and a elevator that only starts moving when called. A simple thing like an elevator in a game is made up of many smaller things. Best practice is to split up tasks like these. This way each function gets tested separately and we can focus on one thing at a time.

Elevator Panel in Editor

On our elevator panel we got a collider setup so it can detect when the player is close.

The elevator button/light is a separate game object.

We assign this elevator light/call button through the inspector.

ElevatorPanel Script

In our elevator panel script we got the following code.

[SerializeField] private Renderer _elevatorLight; private void OnTriggerStay(Collider other)
{
if (other.tag == “Player”)
{
if (Input.GetKeyDown(KeyCode.E))
{
//turn light
_elevatorLight.material.color = Color.blue;
}
}
}

--

--

--

Aspiring developer that’s self-learning Unity & C# to transition to a career with Unity. I got a passion for creating interactive experiences.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Android fundamentals 07.1: AsyncTask

Edge Computing 101

Choosing the Right GraphQL Architecture for Your Project

Day 39/100 Struggling with understanding….

Going the Agile Way!!!

Zenon Pillar Delegation Guide

what i have been waiting for has come !

Creating a “negative” powerup

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Tristan Engel

Tristan Engel

Aspiring developer that’s self-learning Unity & C# to transition to a career with Unity. I got a passion for creating interactive experiences.

More from Medium

2.5D Platformer

Developing A Game Engine with Perl : Part 4 — UEFI vs OpenSuSE Installer

Camera Plugin for Unity

QT 1| QML Property Bindings