Help with froze code & methods

I am new at this so please forgive me… I’ve been playing around with this code for a couple days and it was kind of working but now it seems when i run it Unity just locks up and I have to close it. Can someone please look at this code in my main and tell me whats up. or even tell me how to run the program line by line so i can figure it out? thanks.

Also, I can’t figure out why I cant call methods in other class files from my main, I always get an error. for example if my main script is this:

using UnityEngine;
using System.Collections;
public class Main : MonoBehaviour
{
  CubeCollision();
}

In the above example I am trying to call another script with the class name of CubeCollision. Is that how its done? Instead of calling the name of the class I have tried with the name of the method in the script but it wont work… that’s why I’m dumping everything in my main for now :confused:

Anyways, here is the code from my game below that’s all messed up:
thank you!

using UnityEngine;
using System.Collections;
public class Main : MonoBehaviour {

public GameObject cubeSpawn = null;
public Transform spawnCube = null;

public Transform cubeRed;
public Transform cubeBlue;
public Transform cubeYellow;
public Transform cubeGreen;
public Transform cubePurple;	

public int cubesOnBoard = 0;
float cubeX = -0.5f;
float cubeY = 4.5f;

	void Start ()
		{	

		for (int i = 0; i < 10; i++)
		{
			int cubeColor = Random.Range (1, 5);

			if (cubeColor == 1) {
					spawnCube = cubeRed;
			} else if (cubeColor == 2) {
					spawnCube = cubeBlue;
			} else if (cubeColor == 3) {
					spawnCube = cubeYellow;
			} else if (cubeColor == 4) {
					spawnCube = cubeGreen;
			} else if (cubeColor == 5) {
					spawnCube = cubePurple;
			}
			if (cubeX == 5.0f)
			{
				cubeX = 0.0f;
			}
				else
				{
				cubeX -= - 0.5f;

				}
			Instantiate (spawnCube, new Vector3 (cubeX, cubeY, -10), Quaternion.identity); 

			Debug.Log ("Cube Color is " + cubeColor);
			Debug.Log("cubeX: " + cubeX);

		}
	}	


		void Update()
		{
			
		}
}

I’m not really sure where this CubeCollision class is being declared, or how or what you’re trying to achieve by calling it. Is there a function belonging to it you want to call?

However, from the second piece of code you’ve provided, make sure cubeSpawn has been assigned in the editor. You can’t instantiate a null game object and this is likely to cause Unity to momentarily freeze. You can check if this happens by navigating (if you’re on PC) to C:>Users>“WhicheverUserYouAre”>AppData>Local>Unity>Editor>Editor.txt and check what is outputed to see if it’s giving you an error.