- Home /
Unity Quits Because Of Script!!!
This Is My Script. It's Attached To GUI Texture. When I Click It First Person Controller And F.P. Camera Scripts Are Deactivated And Car And Car Camera Scripts Are Activated (Like You Sit In Car). When I Click GUI Texture Unity Quits (With Windows's "Send Error Report" Window). Please Help!!!!
I Have Windows 7.
var buttonType : String = "Drive/XTools";
var FPController : GameObject;
var car : GameObject;
var carCamera : GameObject;
var fPCamera : GameObject;
var gui1 : GameObject;
var gui2 : GameObject;
var guix : GameObject;
function OnMouseDown ()
{
if(buttonType == "Drive")
{
FPController.GetComponent("Character Controller").enabled = false;
FPController.GetComponent("Mouse Look").enabled = false;
FPController.GetComponent("Character Motor").enabled = false;
FPController.GetComponent("FPSInput Controller").enabled = false;
fPCamera.GetComponent("Camera").enabled = false;
car.GetComponent("Car").enabled = true;
carCamera.GetComponent("Camera").enabled = true;
gui1.GetComponent("GUI Texture").enabled = false;
gui2.GetComponent("GUI Texture").enabled = false;
guix.GetComponent("GUI Texture").enabled = false;
}
}
Often, when Unity quits it's because of an infinite loop in your code. Have you tried to pinpoint the line that's causing the issue? If not, try deleting everything but the first GetComponent, see if that crashes it, and then work from there until it crashes. Once you know the specific line that's causing the issue, if you can't figure it out yourself we'll be much more likely to be able to help you.
I found out that it crashes only on First Person Controller GetComponents.
Answer by DaveA · Sep 25, 2012 at 05:29 PM
Try commenting out one line of code at a (inside the 'if') and try until it stops crashing. The last thing you commented out was the problem. I would guess the problem is there is no "GUI Texture" component, so you are trying to set .enabled on a null reference. You might try "GUITexture" or better
gui1.GetComponent().enabled = true;