This does not make any sense whatsoever. I followed the rules, I referred to my previous successful works, I checked if the variables were static (and they are), I checked the API, I’ve done everything and this code still says “‘finish’ is not a member of ‘function(): void’”.
function OnTriggerEnter (other : Collider){
if (other.gameObject.tag == "Finish"){
Debug.Log("Finish");
Main.finish = true;
}
}
The variable it is referencing is also listed below:
static var finish : boolean = false;
2 Answers
2
Please try to add “public” to your “finish” definition? public static var finish : boolean = false;
I copied your code, placing the main script on a gameobject and the trigger script on a different gameobject. I indeed received the same error as you: “‘finish’ is not a member of ‘function(): void’”. I fixed the problem by placing both, the ‘Main’ script and the script name used by the OnTriggerEnter inside of a class definition. Details below…
Main script:
#pragma strict
public class Main extends MonoBehaviour
{
static var finish : boolean = false;
static var dead : boolean = false;
static var triggered : boolean = false;
var unseenMusic : AudioClip;
var seenMusic : AudioClip;
var colliding : Collider;
var BGM : AudioSource;
private var musicSwapped : boolean = false;
function Start(){
BGM = GetComponent.<AudioSource>();
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
BGM.clip==unseenMusic;
BGM.Play();
}
function Update(){
if (triggered == true && musicSwapped == false){
BGM.volume -= 1 * Time.deltaTime;
if (BGM.volume <= 0.01){
musicSwapped = true;
BGM.clip = seenMusic;
BGM.volume = 1;
BGM.Play();
}
}
if(Input.GetButtonDown("Cancel")){
Application.Quit();
}
if(finish){
Finished();
}
if(dead){
Deaded();
}
}
function Finished(){
Debug.Log("Finished");
if (triggered) {
Application.LoadLevel("GameOverSeen");
} else {
Application.LoadLevel("Victory");
}
}
function Deaded(){
Debug.Log("Dead");
if (triggered) {
Application.LoadLevel("GameOverSeen");
} else {
Application.LoadLevel("GameOver");
}
}
}
Name of the script and class that uses the OnTriggerEnter (I called mine Trigger for testing purposes):
#pragma strict
public class Trigger extends MonoBehaviour
{
function OnTriggerEnter (other : Collider){
if (other.gameObject.tag == "Finish"){
Debug.Log("Finish");
Main.finish = true;
}
}
}
I tried it myself and it worked out fine, so check it and let me know that it works…
You have a class named "Main"? Could be a reserved word. EDIT: Looks like reserved words are few and far between. http://forum.unity3d.com/threads/a-question-about-special-or-reserved-variable-names.94421/
– getyour411Please post your code for classes Main and current class (where OnTriggerEnter locates)
– DenveryI'd love to help but, what @Denvery said...
– ransominkIn C#, I've seen this when there are missing { } - please scan for that.
– getyour411I'm using JavaScript and all the brackets are all there.
– VLunarFangV