Reputation: 77
I was working on a project and I got to the point when I had to write my first script. But when I wrote it, every other script in Unity stopped working.
It says
"the associated script cannot be loaded, please fix any compile errors and assign a valid script.".
I have NOT edited any of the other scripts, so they should work and when I import them in another project they do work. I can't really start over because I have put weeks worth of work into this and if I start over it won't guarantee that it won't happen again.
here is the script
#pragma strict
function Start () {
private var doorIsOpen:boolean=false;
private var doorTimer:float=0.0;
private var currentDoor:gameobject;
public var doorOpenTime:float=3.0;
public var doorOpenSound:AudioClip;
public var doorShutSound:AudioClip;
}
function Update () {
if(dooropen){
doortimer+=time.deltatime;
if(doortimer>dooropentime){
door(doorshutsound,false,"doorshut",currentdoor);
}
doortimer = 0.0;
}
}
}
function door(aClip : audioclip ,opencheck : boolean, animname : string, thisdoor : gameobject ){
audio.playoneshot(aclip);
doorisopen = opencheck;
thisdoor.transform.parent.animation.play(animname);
}
//function opendoor(){
//audio.playoneshot(dooropensound)
//var myoutpost:gameobject = gameobject.find("outpost");
//myoutpost.animation.play("dooropen");
}
function OnControllerColliderHit(hit:ControllerColliderHit){
if(hit.gameObject.tag == "outpostDoor" && doorisopen = false){
currentdoor = hit.gameobject;
door(dooropensound,true,"dooropen",currentdoor);
dooropen = true;
}
}
//function shutdoor(){
//audio.playoneshot(doorshutsound)
//doorisopen = false;
//var myoutpost:gameobject = gameobject.find("outpost");
//myoutpost.animation.play("doorshut");
}
@script requirecomponent(audiosource)
Upvotes: 0
Views: 8204
Reputation: 20038
What you have there will indeed not compile. And given that it will not compile, it will tell you to fix your errors first before you can continue.
So with that determined, let's have a look at your code. Given your function names, I'm assuming you want to extend a MonoBehaviour (that is, make a custom component to attach to a GameObject). In that case you want to write something like:
#pragma strict
class MyCustomComponent extends MonoBehaviour
{
function Start()
{
//Content here
}
function Update()
{
//Content here
}
//etc.
}
This will allow you at add a component named MyCustomComponent to a GameObject in your scene. Secondly, you do not declare your member variables in your Start()
function. You do that outside of it. So
#pragma strict
class MyCustomComponent extends MonoBehaviour
{
private var doorIsOpen : boolean=false;
private var doorTimer : float=0.0;
private var currentDoor : GameObject; //Note the capitalization
public var doorOpenTime : float=3.0;
public var doorOpenSound : AudioClip;
public var doorShutSound : AudioClip;
function Start()
{
//Content here
}
function Update()
{
//Content here
}
//etc.
}
Those are the main causes of the errors you've listed. Making these corrections should get you on your way. And if anything, look at the many tutorials out there to get an idea about how UnityScript works. And of course, always look at the errors you get. They are usually spot on.
Upvotes: 0
Reputation: 1666
The reason you are seeing this is that the non-edited scripts cannot be compiled and loaded because of errors in your new script. You have to make your new script compiler-friendly.
Upvotes: 1