public void ResetRobotObject() { Vector3 robotPosition = Vector3.zero; Quaternion robotRotation = Quaternion.identity; Quaternion cameraRotation = Quaternion.identity; cameraRotation.x = 90f; if (robotObject != null) { robotManager.DestroySensors(); RobotManager.robotCam.transform.SetParent(null); RobotManager.cameraAudioListener.enabled = true; //RobotController.initialized = false; Destroy(robotObject); } robotObject = GameObject.Instantiate(robotPrefab, robotPosition, robotRotation); robotController = robotObject.GetComponent <RobotController>(); robotManager.InitializeRobot(); RobotManager.robotCam.transform.SetParent(robotObject.transform); RobotManager.robotCam.transform.position = robotObject.transform.position + new Vector3(0f, 500f, 0f); RobotManager.robotCam.transform.rotation = robotObject.transform.rotation; RobotManager.robotCam.transform.Rotate(new Vector3(90f, 0f, 0f)); Debug.Log(RobotManager.robotCam.name + " has parent " + RobotManager.robotCam.transform.parent.name); //Debug.Log("ResetRobotObject(): position - " + robotObject.transform.position.ToString() + " orientation - " + robotObject.transform.rotation.ToString()); //robotObject.transform.SetPositionAndRotation(Vector3.zero, Quaternion.identity); }
public void ResetRobotObject() { Vector3 robotPosition = Vector3.zero; Quaternion robotRotation = Quaternion.identity; Quaternion cameraRotation = Quaternion.identity; cameraRotation.x = 90f; //Start by trying to find a robot if it already exists. robotObject = GameObject.Find("Robot"); //If the robot does exist, destroy it. if (robotObject != null) { robotManager.DestroySensors(); Destroy(robotObject); RobotManager.robotCam.transform.SetParent(null); RobotManager.cameraAudioListener.enabled = true; Debug.Log("ResetRobotObject() - cameraAudioListener.enabled? " + RobotManager.cameraAudioListener.enabled); //RobotController.initialized = false; } //Whether a previous robot existed or not, instantiate a new one. robotObject = GameObject.Instantiate(robotPrefab, robotPosition, robotRotation); robotController = robotObject.GetComponent <RobotController>(); robotManager.InitializeRobot(); SetupCameraPOV(); Debug.Log(RobotManager.robotCam.name + " has parent " + RobotManager.robotCam.transform.parent.name); //Debug.Log("ResetRobotObject(): position - " + robotObject.transform.position.ToString() + " orientation - " + robotObject.transform.rotation.ToString()); //robotObject.transform.SetPositionAndRotation(Vector3.zero, Quaternion.identity); }