Day 79 — Creating a Moving Platform in Unity

public Transform pointA, pointB;
private float _speed = 2.0f;
private bool _reverse = false;
void Update()
{
if (_reverse == false)
{
transform.position = Vector3.MoveTowards(transform.position, pointB.position, _speed * Time.deltaTime);
}
else
{
transform.position = Vector3.MoveTowards(transform.position, pointA.position, _speed * Time.deltaTime);
}
if (transform.position == pointB.position)
{
_reverse = true;
}
else if (transform.position == pointA.position)
{
_reverse = false;
}
}
private void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
other.transform.parent = this.transform;
}
}
private void OnTriggerExit(Collider other)
{
if (other.tag == "Player")
{
other.transform.parent = null;
}
}

--

--

--

Hey and welcome! My name is Connor and my goal here is to put out a daily post for a full year about my game development journey.

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

Recommended from Medium

Flutter: FCM notifications on Mobile and Web

Kubernetes: five steps to well-behaved apps

Detect Language of Text using NLP in C/C++

HackTheBox: Bounty Hunter (Walkthrough)

Performing runtime type-checking in Python

Building Multiple QR Codes Scanner Using Swing AVFoundation

Installing HAProxy in MacOs BigSur

Updates of Chemix Ecosystem Project ( Mar 15th to Apr 24th, 2022 )

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
Connor Fullarton

Connor Fullarton

Hey and welcome! My name is Connor and my goal here is to put out a daily post for a full year about my game development journey.

More from Medium

Week 24: How to add SFX to you game without going mad

My first game in Unity

Working with Unity Ads

Introducing Stream’s New SDK for the Unity Gaming Engine