I am trying to modify the default character motor script to add swimming capabilities. I have a first person controller and an island scene. Since I have the free version of Unity, I have the water as being a square plane at y = 1010 with a script to create waves. The script that I attached to the main camera was something like this:
static var isUnderwater : boolean;
function Update(){
var underwater = 1010;
if(transform.position.y < underwater){
isUnderwater = true;
}
else{
isUnderwater = false;
}
if(isUnderwater == false){
audio.Play();
}
}
I also had the character motor script attached to the first person controller. Obviously that is too long to post here but in the private function UpdateFunction() on line 185, I wanted to put
if(UnderwaterScript.isUnderwater == true){
canControl = false;
}
When I try to compile the script it throws an error that says “Unknown Identifier: ‘UnderwaterScript’.” I know what this means (It doesn’t know what UnderwaterScript is.), but I don’t know how to fix it. I’ve tried all different capitalization of UnderwaterScript, and i’ve tried changing the isUnderwater variable to var, static var, and public var. All the other posts that I looked at simply say that you need to use the name of the script that the global variable is located in followed by a dot, followed by the name of the variable. I did that. Could someone please help me?