Make character stay on moving platform?

I was following a youtube tutorial on how to make a platform that moves horizontally between two points. The guy is using C#, and already has a whole script for character movement, which he wrote in previous tutorials. Here is the tutorial video (he starts writing the code at 19:00).

My issue is, that I like how realistic the movement of the “RobotBoy” (which is in the 2D assets) prefab feels, so I wanted to implement the code from the tutorial, into the “Platformer2DUserControl” script which also comes with the 2D assets, instead of writing his entire code, and using that.

I know this question must’ve been asked a million times on here, but as you can tell, my issue isn’t writing the code, it’s implementing it.

I am currently learning JavaScript in college, and Java at home in my own time, so I would really love a simple solution instead of an advice to read tutorials about C#, as I’m already very busy, and this is just for a very simple game that I started making for fun.

I’ll save you the trouble of looking up the 2D control script, and watching the video, and I’ll post both codes below.

Here is the code from the RobotBoy prefab:

using System;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;

namespace UnityStandardAssets._2D
    [RequireComponent(typeof (PlatformerCharacter2D))]
    public class Platformer2DUserControl : MonoBehaviour
        private PlatformerCharacter2D m_Character;
        private bool m_Jump;

        private void Awake()
            m_Character = GetComponent<PlatformerCharacter2D>();

        private void Update()
            if (!m_Jump)
                // Read the jump input in Update so button presses aren't missed.
                m_Jump = CrossPlatformInputManager.GetButtonDown("Jump");

        private void FixedUpdate()
            // Read the inputs.
            bool crouch = Input.GetKey(KeyCode.LeftControl);
            float h = CrossPlatformInputManager.GetAxis("Horizontal");
            // Pass all parameters to the character control script.
            m_Character.Move(h, crouch, m_Jump);
            m_Jump = false;

And here is the code from the tutorial, which I want to implement into the prefab code:

void OnCollisionEnter2D(Collision2D other)
	if(other.transform.tag == "MovingPlatform")
		transform.parent = null;

The “MovingPlatform” just refers to an empty object which is the parent of the platform sprite and 2 other empty objects which are used to set the two points between which the platform will move.

So my question is, how do I implement his code, into the prefab’s controller code (aka where do I put it)?

P.S. The reason I called the question “Make character stay on moving platform?” and not something like “How to implement code into another code?”, is because it’s more clear I want to achieve in the end.

There’s a real great collection of tutorials for 2d platforming in Unity, by Sebastian Lague on youtube. I recommend you start from the beginning but what you’re looking for could be answered here link text

Stick with it, you may have to watch a few over and over again and try not to let the math scare you away, you may learn something!

Hope that helps!