I Just Copy / Pasted a Script from the Unity Docs, Why isn’t it Working?

I just tried to copy/paste a script from the Unity Website – specifically a script for quitting the game when the player presses Escape. But then it didn’t work… what went wrong? Here’s the process I went through to discover and correct the issue:

  1. I created a new script called “GameController”

  2. I pasted in the code from the website:

  3. but for some reason, it didn’t work.

    The associate script can not be loaded. Please fix any compile errors and assign a valid script.

  4. I tried removing and re-adding the script, and got this error:

    Can't add script component 'GameController' because the script class cannot be found. Make sure that there are no compile errors and that the file name and class name match.

  5. After a bit of poking, I disovered it was this line that got me in trouble:

public class ExampleClass : MonoBehaviour {

What’s wrong with this line? The filename was GameController.cs but the class name was ExampleClass. So, how do we fix it? Either rename your file to ExampleClass.cs or modify the code to match the name of the script (which is what I recommend):

public class GameController : MonoBehaviour {

This will also sometimes happen when you rename a script file, because Unity isn’t smart enough to refactor (aka auto-update the names in) your source code.

Adding Text to a Unity Game

To add a text UI element to your game:

  1. Hierarchy > Create > UI > Text
  2. A Text object will be added to your hierarchy.

To place the text in the upper left corner

  • Select the text object, and examine it in the inspector:

  • Click on the “Anchor Presets”

  • Hold down Shift + Alt and click on the upper left option

Making Objects Float Up & Down in Unity

Ever wanted to make an object float up and down while spinning in Unity? Well, I’ve written a script for that.

End Result of Script


  1. Select an object in your Unity project.
  2. Add Component > New Script
    1. Name: Floater
    2. Language: C-Sharp
  3. Edit the script
  4. Copy & Paste the code below into your script editor.
  5. Save the script.
  6. Tweak settings to your heart’s content

// Floater v0.0.2
// by Donovan Keith
// [MIT License](https://opensource.org/licenses/MIT)

using UnityEngine;
using System.Collections;

// Makes objects float up & down while gently spinning.
public class Floater : MonoBehaviour {
	// User Inputs
	public float degreesPerSecond = 15.0f;
	public float amplitude = 0.5f;
	public float frequency = 1f;

	// Position Storage Variables
	Vector3 posOffset = new Vector3 ();
	Vector3 tempPos = new Vector3 ();

	// Use this for initialization
	void Start () {
		// Store the starting position & rotation of the object
		posOffset = transform.position;
	// Update is called once per frame
	void Update () {
		// Spin object around Y-Axis
		transform.Rotate(new Vector3(0f, Time.deltaTime * degreesPerSecond, 0f), Space.World);

		// Float up/down with a Sin()
		tempPos = posOffset;
		tempPos.y += Mathf.Sin (Time.fixedTime * Mathf.PI * frequency) * amplitude;

		transform.position = tempPos;

Getting the Ball Rolling with Roll-A-Ball

Alright, this one is nearly cheating as I’ve built this project a couple times cheap nfl jerseys now on my own and in class with students. That said, it’s Бердянск been a bit since for I used Unity, so a refresher of the basics seems in order.

    • Introduction to Roll-a-Ball
    • Setting up the Game
      White sphere on blue ground.
    • Moving the Player
  • Creating Collectable Objects


  • Folders are automatically created based on Project Name, no need to create a folder for your project w/ the same name.
  • Using SourceTree by Atlassian to do local Git version control.
  • Add Physics with the Rigid Body Component. Inspector > Add Component > Physics > Rigid Body
  • Collider. Inspector > Dog Add How Component > Physics > Sphere Collider
  • CamelCase -> Camel Case
  • Add scripts directly to the object if you want to add & attach them in one step. But, you need to move it to your Scripts folder manually.
  • Cmd + ' | Open Reference
  • public GameObject camera will create with a field where you can drag in a target object.
  • Playing Audio


  • Add Object: Rt Click on the Hierarchy View > Game Object > 3D Object > …
  • Reset Position / Scale / Rotation: Inspector > Transform > Gear Icon > Reset
  • Create a Material:
    • Ensure you have a Materials folder
    • Project / Materials
      • Right-Click > Create > Material


  • Frame Selected | F

Unity 3D for Cinema 4D Users

Leverage your knowledge with of Cinema 4D to quickly get up to speed with Unity 3D

Manipulating Objects

  • Move Tool: W
  • Rotate Tool: E
  • Scale Tool: R1er
  • Quantize Movement / Rotation
  • Add Object at Origin
    • One cheap jerseys of the bigger differences between Unity and C4D is that new objects default to the camera’s focal point instead of the world origin. While this is cheap nba jerseys a


  • Material Manager -> Project View
  • Object Manager -> Hierarchy View
  • Attributes Manager -> Inspector



  • Color -> Albedo

Learning VR Development with Unity and Cinema 4D

One of cheap jerseys the bigger initiatives at Cineversity this year is to build up training and tools for creating cheap jerseys Virtual Reality projects with Cinema 4D. There’s no better way to learn than doing – so I’m going to be cataloguing my efforts here. I’ve created a Beeminder with the About not-too-ambitious goal of spending at least Collectibles one hour a day during the work-week upping my skills in the VR world.

Starting with, completing the following Tutorials:

I also cheap jerseys China just found cheap mlb jerseys this list of unity learning resources that may be a better place to look Proxy until this list gets built out over time.