Both if and else are running, because else condition is met after if

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class CubeManager : MonoBehaviour {

	public GameObject CubeGet;
	public List <GameObject> Cubes = new List <GameObject> ();
	public int CurrentCube;
	public int MinCubes;
	public int MaxCubes;
	public int MinX;
	public int MaxX;
	public int MinY;
	public int MaxY;
	public int [] AllSortOrders;
	public int HighestLayer;
	public Sprite [] Sprites;

	void Start () {
		int ActionGet = PlayerPrefs.GetInt ("Cube Manager Action");
		if (ActionGet == 0)
			int CubesToSpawn = Random.Range (MinCubes, MaxCubes);
			for (int CubesSpawned = 0; CubesSpawned < CubesToSpawn + 1; CubesSpawned ++) 
				Instantiate (CubeGet, new Vector3 (Random.Range (MinX, MaxX + 1), Random.Range (MinY, MaxY + 1), 1), Quaternion.identity);
				if (CubesSpawned == CubesToSpawn)
					CurrentCube = 1;
					Camera.main.transform.position = new Vector3 (Cubes [1].transform.position.x, Cubes [1].transform.position.y, -1);
			PlayerPrefs.SetInt ("Cube Manager Action", 1);
			int CubeCount = PlayerPrefs.GetInt ("Cube Count");
			for (int CubeRespawn = 1; CubeRespawn < CubeCount + 1; CubeRespawn ++)
				Instantiate (CubeGet,, Quaternion.identity);
			CurrentCube = PlayerPrefs.GetInt ("Current Cube");

	void OnApplicationQuit () {
		PlayerPrefs.SetInt ("Cube Count", Cubes.Count);

Where can I put

PlayerPrefs.SetInt ("Cube Manager Action", 1);

in a place that doesn’t trigger the else as well?

You use PlayerPrefs to store whether your cubes have been spawned in this run (Play-Mode, game start). PlayerPrefs persist between runs (because they are data on disk, not in the RAM). Means: after one run, you will NEVER EVER get into the if-part again, but straight to the else part. To fix this, you’d have to reset your PlayerPrefs after each run (either deleting the created PlayerPrefs or setting all your PlayerPrefs to your standard value in the OnDestroy()-method) or, instead of using PlayerPrefs, store your progress in a member variable of CubeManager (preferrably, a bool). If you want to spawn your cubes in only one run and have them persist through runs (in which PlayerPrefs to check for Instantiation like you do are valid) I suggest saving their data to disk as well (in some data-container-format like xml, PlayerPrefs are not made to store large amount of data).

But there are a few other things that bother me as well:

You instantiate cubes but don’t add references to said cubes to your cube list. Then you access cubes in your list… If the cubes do not add themselves to the list, this will throw Exceptions. If they do not add themselves, then swap line 27 with this:

GameObject go = Instantiate(CubeGet, new Vector3 (Random.Range (MinX, MaxX + 1), Random.Range (MinY, MaxY + 1), 1), Quaternion.identity) as GameObject;

You have to do similar steps in line 41.

Your for-loop in line 25 loops CubesToSpawn + 1 times… remove the + 1 if you want it to loop CubesToSpawn times. Same for line 39.

The if-clause in line 28 (where you check whether the current element is the last) is obsolete. Just put everything that is in there below for-loop (where you have PlayerPrefs.SetInt (“Cube Manager Action”, 1):wink: and it will automatically be called after you have instantiated all your cubes (like before)

You start accessing the list at index 1. In most (if not all) programming languages that feature Arrays or Lists, the first element is at index 0. You basically skip the first element and access the second when you set the camera in line 31. Most likely this is behaviour you don’t want and if you only spawn 1 cube, this will throw Exceptions.

Since the else-clause does not seem to be final (assuming you want to load your cubes from disk which is way out of the scope of this answer) I can only say that you seem to be accessing a PlayerPref-value (“Current Cube”) you did not set previously.

P.S.: If my answer sounded rude I apologize. I tend to be painfully direct.