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 question was closed Jun 25, 2014 at 01:43 PM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by frogi16 · Jun 24, 2014 at 07:36 PM · variables

What's wrong in "simple" script?

I have simple problem, but I wasn't found good answer. I have two (in my opinion) good scripts, but they are making errors (variables are in other language, sorry).

 using UnityEngine;
 using System.Collections;
 
 public class GłówneInfoGeneracji : MonoBehaviour {
 
     public int MaksymalnaIlośćPomieszeń;
     public int ObecnaIlośćPomieszczeń;
     
     void Start () 
     {
         MaksymalnaIlośćPomieszeń=Random.Range (50,100);
     }
 
     void Update () 
     {
     
     }
 }

 using UnityEngine;
 using System.Collections;
 
 public class GenerowanieLosowe : MonoBehaviour {
     
     GameObject pomieszczenieSpawn=GameObject.Find ("PomieszczenieSpawn");
 
     GłówneInfoGeneracji główneInfoGeneracji=pomieszczenieSpawn.GetComponent<GłówneInfoGeneracji>();
 
     int MaksymalnaIlośćPomieszczeń=główneInfoGeneracji.MaksymalnaIlośćPomieszeń;
 
     int AktualnaIlośćPomieszczeń;
 
     void Start () 
     {
         print (MaksymalnaIlośćPomieszczeń);
     }
 
     void Update () 
     {
     
     }
 }

Error: Assets/Prefaby/Pomieszczenia/GenerowanieLosowe.cs(8,49): error CS0236: A field initializer cannot reference the nonstatic field, method, or property GenerowanieLosowe.pomieszczenieSpawn' Assets/Prefaby/Pomieszczenia/GenerowanieLosowe.cs(10,40): error CS0236: A field initializer cannot reference the nonstatic field, method, or property GenerowanieLosowe.g��wneInfoGeneracji'

I know, this issue was raided many times, but I really musn't find errors. I'm sorry for your time and please help.

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 jefjohms · Jun 24, 2014 at 07:42 PM 0
Share

In the future, google the exact error message and you'll usually get pointed in right direction.

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by meat5000 · Jun 24, 2014 at 07:36 PM

Perform your Find and GetComponent within Start() function instead of in the Declarations.

Comment
Add comment · Show 2 · 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 frogi16 · Jun 25, 2014 at 01:26 PM 0
Share

Thanks, it's working.

avatar image meat5000 ♦ · Jun 25, 2014 at 01:31 PM 0
Share

No problem. Please accept the answer :)

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Creating a 'rotation' system 1 Answer

[C# Code] Why am I getting this error??? 1 Answer

How do I create a bullet whose velocity and direction is affected by the velocity and direction of its source? 1 Answer

Changing a variable in another script over the network 1 Answer

join two scripts to use one var in both scripts 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