Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by VLunarFangV · Aug 18, 2015 at 03:08 PM · javascriptbooleanbce0019

Referencing external static variable with no success

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;

Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image getyour411 · Aug 18, 2015 at 04:19 PM 0
Share

You have a class named "$$anonymous$$ain"? 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/

avatar image Denvery · Aug 18, 2015 at 05:59 PM 1
Share

Please post your code for classes $$anonymous$$ain and current class (where OnTriggerEnter locates)

avatar image ransomink · Aug 19, 2015 at 04:03 AM 0
Share

I'd love to help but, what @Denvery said...

avatar image VLunarFangV · Aug 19, 2015 at 05:36 AM 0
Share

I have another code calling on one of $$anonymous$$ain's static variables and that one has no issues at all, so it isn't a reserved word.

Here's the code for $$anonymous$$ain:

 static var finish : boolean = false;
 static var dead : boolean = false;
 static var triggered : boolean = false;
 private var musicSwapped : boolean = false;
 var unseen$$anonymous$$usic : AudioClip;
 var seen$$anonymous$$usic : AudioClip;
 var colliding : Collider;
 var BG$$anonymous$$ : AudioSource;
 
 
 function Start(){
     BG$$anonymous$$ = GetComponent.<AudioSource>();
     Cursor.visible = false;
     Cursor.lockState = CursorLock$$anonymous$$ode.Locked;
     BG$$anonymous$$.clip==unseen$$anonymous$$usic;
     BG$$anonymous$$.Play();
 }
 
 function Update(){
     if (triggered == true && musicSwapped == false){ 
         BG$$anonymous$$.volume -= 1 * Time.deltaTime;
         if (BG$$anonymous$$.volume <= 0.01){
             musicSwapped = true;
             BG$$anonymous$$.clip = seen$$anonymous$$usic;
             BG$$anonymous$$.volume = 1;
             BG$$anonymous$$.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");
     }
 }

Code for OnTriggerEnter was listed but I messed it up so it looked like unreadable gibberish. I've fixed the appearance so you can actually read it.

avatar image getyour411 · Aug 19, 2015 at 08:07 AM 0
Share

In C#, I've seen this when there are missing { } - please scan for that.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by ransomink · Aug 20, 2015 at 04:00 AM

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...

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image VLunarFangV · Aug 21, 2015 at 01:41 PM 0
Share

It looks like it was modified with C#.

avatar image ransomink · Aug 21, 2015 at 04:27 PM 0
Share

Do you mean your code and that's what the error was or $$anonymous$$e? If you're referring to my code, it does not use C#, I only know and use UnityScript.

I copied and pasted your code into my visual editor. What I did was encapsulate the code inside of a class definition using 'public class "ClassName" extends $$anonymous$$onoBehaviour {}'.

Besides that I reorganized the order of your variables placing first: static, public, then private. (Just how I do my work, that's all.)

avatar image ransomink · Aug 22, 2015 at 12:40 AM 0
Share

I think I see your confusion: C# scripts must have a class definition with the same class name as the script; UnityScript extends $$anonymous$$onoBehaviour by default so there is no need for a class definition. Certain circumstances you need the class definition, i.e. inheritance and interfacing.

I added the class definition to check if it worked and it did...

avatar image VLunarFangV · Aug 24, 2015 at 06:44 PM 0
Share

I've finally gotten around to plugging in the code and it works without a problem. Don't know how it works, but I'll look into that later on.

avatar image
1

Answer by Denvery · Aug 19, 2015 at 09:54 AM

Please try to add "public" to your "finish" definition? public static var finish : boolean = false;

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image cyryviv · Aug 19, 2015 at 10:39 AM 0
Share

Thank you so much....

avatar image Denvery · Aug 19, 2015 at 11:19 AM 0
Share

Sorry, is your $$anonymous$$ain is a class? So is it defined like this:public class $$anonymous$$ain extends $$anonymous$$onoBehaviour ?

avatar image ransomink · Aug 20, 2015 at 04:04 AM 2
Share

In UnityScript, variables are public by default unless noted as private, so it doesn't have any effect...

avatar image fafase · Aug 20, 2015 at 05:42 AM 0
Share

And it extends $$anonymous$$onoBehaviour by default too.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

28 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Simple gun draw script not working 1 Answer

JS Unity Boolean 'not possible to evoke an expression of type 'boolean'' 1 Answer

Why my game just win all the way? 1 Answer

Stuck while solving a Coroutine problem 0 Answers

how to know which script you change? 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges