Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Jake_002 · Jun 05, 2012 at 01:07 AM · variablesyntax-errorstatic variableglobal variable

Global Variable Error

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?

Comment
Add comment
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

1 Reply

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

Answer by Bunny83 · Jun 05, 2012 at 01:14 AM

It's funny, usually the people have problems because they mix different languages so they need to place the different files in different compiling groups. In your case that's actually the problem. The character motor script is usually located in the Standard Assets folder and therefore compiled before everything else. Your own custom script is propably somewhere in your assets folder and compiled after the character motor script. That means it isn't available to the character motor script.

So you should either move your own script into the Standard Assets folder or move the character motor script out of that folder so both files are in the same group.

For more information see the compilation order page

Comment
Add comment · Show 3 · 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 hijinxbassist · Jun 05, 2012 at 01:23 AM 0
Share

Are you referring to me?!? lol. Another good use for compilation order, custom script/asset script. great to know. Thanks Bunny

avatar image Jake_002 · Jun 05, 2012 at 01:28 AM 0
Share

Ok. I didn't know that. Thanks for the info. It works now.

avatar image Bunny83 · Jun 05, 2012 at 09:47 AM 0
Share

@hijinxbassist: No, i wasn't referring to you :) It's really a quite common issues which propably seems a bit strange for new users. However, this is the first time that it's the other way round ;)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Error "There is already a local variable with the name 'obstacle'." How can I make it work? 2 Answers

How to make variable accessible by other scripts but not visible in editor? 1 Answer

Static variable for accessing global object? 3 Answers

(PLAYMAKER) How to synchronize global variables to another visual scripting? (like Uscript or Behavior Machine Pro) 0 Answers

Caching global vareiables? (n00b question) 1 Answer


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