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 /
avatar image
0
Question by oz m · May 22, 2010 at 08:04 PM · variablesstaticbce0005unknown-identifier

Static variables problem

i have a health bar script, and i made a static variable in it. i made it so a monster follows the main character. The monster's code also has a static variable. In the main character's code, i want to make it so when the monster hits it, it does the health bar's static variable minus the monster's static variable. the health bar's script is called bar, and the monster's script is called beholder. here's the code for the character:

var speed : float = 6.0; var jumpSpeed : float = 8.0; var turnSpeed : float = 3.0; var gravity : float = 20.0;

bar.barDisplay = 100; beholder.damage = 5;

private var moveDirection = Vector3.zero; private var turnDirection : float = 0; private var grounded : boolean = false;

function OnTriggerEnter(hit : Collider) { if(hit.gameObject.tag == "Beholder") { Debug.Log("hit for " + beholder.damage + "points"); bar.barDisplay -= beholder.damage; } } function FixedUpdate() { if (grounded) { // We are grounded, so recalculate movedirection directly from axes moveDirection = new Vector3(0, 0, Input.GetAxis("Vertical")); moveDirection = transform.TransformDirection(moveDirection); moveDirection *= speed;

     turnDirection = Input.GetAxis("Horizontal");
     transform.Rotate(0, turnDirection * turnSpeed ,0);

     if (Input.GetButton ("Jump")) {
         moveDirection.y = jumpSpeed;
     }
 }

 // Apply gravity
 moveDirection.y -= gravity * Time.deltaTime;

 // Move the controller
 var controller : CharacterController = GetComponent(CharacterController);
 var flags = controller.Move(moveDirection * Time.deltaTime);
 grounded = (flags & CollisionFlags.CollidedBelow) != 0;

}

@script RequireComponent(CharacterController)

everything else works, but unity says that the identifiers beholder and bar are unknown...

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
5
Best Answer

Answer by Jessy · May 22, 2010 at 08:20 PM

"beholder" and "bar" are not the names of your classes. (That is, they are not the names of the scripts.) The naming convention in Unity is to use uppercase for the first letter of a class's name. So here is what you would use in the script you posted:

Bar.barDisplay = 100; 
Beholder.damage = 5;

And in those scripts, named Bar, and Beholder, respectively, you need these declarations:

static var barDisplay;
static var damage;
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 oz m · May 22, 2010 at 08:27 PM 0
Share

thanks, i didn't know that

avatar image oz m · May 22, 2010 at 08:31 PM 0
Share

it didn't work.

avatar image oz m · May 22, 2010 at 08:47 PM 0
Share

actually yes it did now, thanks

avatar image schwertfisch · Dec 04, 2010 at 05:03 PM 0
Share

useful to me too - thanks

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

No one has followed this question yet.

Related Questions

'Unknown Identifier' - cannot recognize other scripts 1 Answer

Problems with variables across scripts 0 Answers

Access variables,method from a Mono Behaviour without static use. -1 Answers

How to make a variable for color affect another object 1 Answer

BCE0005: Unknown identifier 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