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

Feature Flags in the Software Release Life Cycle

Woman sitting in front of a computer coding.

FlutterForce — #Week 108

Beginner’s Big O for Swift Developers

How I finished the entire freeCodeCamp curriculum in 9 months while working full time

Designing a Platform

Coding on a Chromebook

Bluzelle Community Project Showcase — Instant Notary App

Easiest Steps To Build A Face Filter App With Flutter and Deep AR

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

Creating A Retro Game Over Behavior

High Definition Rendering Pipeline in Unity

Level Design in Unity Part 1: The Floor

Adding another powerup — Shields