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 Fa6ex · Nov 17, 2014 at 02:31 PM · objectreference

Error CS0120

Hello.

A few days ago, I set myself a goal: to create a 3D game. For that, I started learning how to use Unity and C#. Everything went more or less smoothly, with a few bumps here and there. However, yesterday I ran into a metaphorical wall that I've yet to get through.

The problem is the following: I created a script with a class holding several variables and an array to associate them. Then I created another script, which managed the player's health, that needed to access one of those variables. However, when I tried to do that, I got the error described in the title. I researched for a whole day, trying to solve the problem, with no luck. I tried using GetComponent, but there was no difference. Then I tried making everything in question static. The error in question went away, but then I got not one, but two different errors: CS0709 and CS0713.

Here's the code I used, for the first script:

 public class Pokemon : MonoBehaviour
 {
 ...
 public int health;
 ...
 
 void Start () {
 Pokemon[] Players = new Pokemon[20];
 ...
 Players [0].health = 2000;


And then, on the other script:

 public class Health_Bar : Pokemon
 {
 private int mHealth;
 private int cHealth;
 ...
 void Start ()
 {
 mHealth = Pokemon.Players [0].health;
 cHealth = Pokemon.Players [0].health;
 ...
 

What am I doing wrong? How do I fix this? Please help me, I'm kind of losing my motivation here :(

Comment
Add comment · Show 1
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 AlwaysSunny · Nov 17, 2014 at 02:10 PM 1
Share

When posting about errors, please include the entire error message. Note that most error messages tell you the line on which the error is located (the first number in parenthesis). If you can't figure out a specific error even when you know the line number, ensure you indicate the specific line to us in your posted code.

You seem to be misunderstanding some basics. The best advice I can offer is to spend time going through Unity tutorials and learning C# in earnest. Here's a great resource for learning C# fundamentals super quick: http://rbwhitaker.wikidot.com/c-sharp-tutorials

The big thing that stands out as wrong is that your health bar script shouldn't inherit from pokemon.

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Having script accessing issues 2 Answers

NullReferenceException: Object reference not set to an instance of an object 1 Answer

Tagging object while instating not working. 3 Answers

Change 3D Object by pressing Gui Button 1 Answer

Unity return error message like method not a member of Object class 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