public void ActOnCube(GameCube gc) { if (gc.CurrentlyPointingAt == this) { //If placing if (currentID >= 0) { IPlaceable placeable = buildables [currentID].GetComponent <IPlaceable> (); GameCube.PlacementError pe = gc.CanPlace(placeable); if (pe == GameCube.PlacementError.None) { GameObject p = Instantiate(buildables [currentID]); //most of the spawning process is handled by the gamecube gc.Occupying = p; if (p.GetComponent <AudioSource>() != null) { p.GetComponent <AudioSource> ().Play(); } //spend resources ResourceManager.Instance.Spend(p.GetComponent <IPlaceable> ().BuildCost); EnemyPathManager.Instance.ShouldRecalcPathBlocked(gc); } else { //failure cases Debug.Log(pe.ToString()); } } else { GameCube.RemoveError re = gc.CanRemove(); if (re == GameCube.RemoveError.None) { ResourceManager.Instance.AddResources(gc.Occupying.GetComponent <IPlaceable> ().BuildCost); gc.Occupying = null; } else { //failure case Debug.Log(re.ToString()); } } } else { Debug.Log("Another build tool is pointed at this cube first!"); } }