using UnityEngine;
using System.Collections;
public class GameHandler : MonoBehaviour {
public GameObject playerPrefab;
public GameObject playerCameraPrefab;
public GameObject player;
public GameObject playerCamera;
// Use this for initialization
void Awake () {
player = Instantiate(playerPrefab,new Vector3(5,1,5),Quaternion.identity) as GameObject;
playerCamera = Instantiate(playerCameraPrefab,Vector3.up,Quaternion.identity) as GameObject;
}
// Update is called once per frame
void Update () {
}
}
using UnityEngine;
using System.Collections; using System.Collections.Generic;
public class EarthMagic : MonoBehaviour {
public GameHandler gameHandler;
public GameObject EarthMagicWall;
public PlayerMovement PM;
public UIControls UI;
public Transform spinner;
public List<Transform> circleStones = new List<Transform>();
// Use this for initialization
void Start () {
//connect to the gameHandler
gameHandler = GameObject.Find ("WorldHandler").GetComponent("GameHandler") as GameHandler;
PM = transform.GetComponent("PlayerMovement") as PlayerMovement;
UI = transform.GetComponent("UIControls") as UIControls;
}
// Update is called once per frame
void Update () {
if(UI.gamePaused == false) {
if(Input.GetButtonDown("Channel")) {
if(PM.isGrounded == true) {
Vector3 checkPosition = transform.position + (transform.forward * 3);
// Debug.DrawRay(transform.position, checkPosition, Color.blue, 20);
// Debug.DrawRay(checkPosition, transform.TransformDirection (Vector3.down), Color.red, 20);
RaycastHit hit;
if (Physics.Raycast(checkPosition, transform.TransformDirection (Vector3.down), out hit, 5)) {
if(hit.collider.name == "Terrain") {
Instantiate(EarthMagicWall, hit.point, transform.rotation);
}
}
}
}
if(Input.GetMouseButtonDown(0)) {
if(circleStones.Count > 0) {
Transform temp = circleStones[0].transform;
circleStones.RemoveAt(0);
temp.parent = null;
temp.rigidbody.AddForce(Camera.main.transform.up * 20);
}
}
ControlRocks ();
}
}
void ControlRocks() {
foreach(Transform circleStone in circleStones) {
switch(circleStones.Count) {
case 1: case 2:
if(circleStones.IndexOf(circleStone) == 1) {
circleStone.transform.localPosition = new Vector3(0,0, 2);
} else {
circleStone.transform.localPosition = new Vector3(0,0, -2);
}
break;
case 3:
if(circleStones.IndexOf(circleStone) == 1) {
circleStone.transform.localPosition = new Vector3(0,0, 2);
} else if(circleStones.IndexOf(circleStone) == 2) {
circleStone.transform.localPosition = new Vector3(Mathf.Sqrt(2),0, (Mathf.Sqrt(2) * -1));
} else {
circleStone.transform.localPosition = new Vector3((Mathf.Sqrt(2) * -1),0, (Mathf.Sqrt(2) * -1));
}
break;
case 4:
if(circleStones.IndexOf(circleStone) == 1) {
circleStone.transform.localPosition = new Vector3(Mathf.Sqrt(2),0, Mathf.Sqrt(2));
} else if(circleStones.IndexOf(circleStone) == 2) {
circleStone.transform.localPosition = new Vector3(Mathf.Sqrt(2),0, (Mathf.Sqrt(2) * -1));
} else if(circleStones.IndexOf(circleStone) == 3){
circleStone.transform.localPosition = new Vector3((Mathf.Sqrt(2) * -1),0, (Mathf.Sqrt(2) * -1));
} else {
circleStone.transform.localPosition = new Vector3((Mathf.Sqrt(2) * -1),0, Mathf.Sqrt(2));
}
break;
case 5:
if(circleStones.IndexOf(circleStone) == 1) {
circleStone.transform.localPosition = new Vector3(0,0, 2);
} else if(circleStones.IndexOf(circleStone) == 2) {
circleStone.transform.localPosition = new Vector3(1.9f,0, 0.62f);
} else if(circleStones.IndexOf(circleStone) == 3){
circleStone.transform.localPosition = new Vector3(1.18f,0, -1.61f);
} else if(circleStones.IndexOf(circleStone) == 4){
circleStone.transform.localPosition = new Vector3(-1.18f,0, -1.61f);
} else {
circleStone.transform.localPosition = new Vector3(-1.9f,0, 0.62f);
}
break;
}
Stone stone = circleStone.gameObject.GetComponent("Stone") as Stone;
if(!stone.isRigid) {
Rigidbody shardRigidBody = stone.gameObject.AddComponent<Rigidbody>();
shardRigidBody.mass = 5;
stone.isRigid = true;
}
}
}
}
So the error above occurs at line 63 in EarthMagic. I've solved this type of error before but I don't really understand it this time. This code was working before and I did not change that entire function. I did however start to instantiate my player and camera rather than simply place them in the editor. I'm sure this is the cause of the problem but I don't really know how to fix this. Any ideas?