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 /
  • Help Room /
avatar image
0
Question by MerlinsMaster · Jul 24, 2016 at 08:02 PM · for-looparray of gameobjects

error CS0201

Hey guys,

I'm trying to get several prefabs to instantiate under several parent objects.

This is my code:

 public GameObject [] shipSystem;
 
 public Transform [] hardPoint;
 
 void Start ()
    {
       for (int i = 0; i = 1; i++)
          {
             GameObject [i] installSystem = (GameObject)GameObject.Instantiate(shipSystem[i]);
             installSystem [i].transform.parent = hardPoint[i].transform;
          }
    }

And I get this compiler error:

error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement

Does anyone know what I'm doing wrong?

Thanks.

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

Answer by btmedia14 · Jul 24, 2016 at 08:21 PM

The for loop expression needs a loop test condition. Instead it is showing a second assignment:

   for (int i = 0; i = 1; i++)

Usually the form is something like:

   for (int i = 0; i  < endValue; i++)
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 MerlinsMaster · Jul 24, 2016 at 09:10 PM 0
Share

Thank you for pointing that out. I can't believe I didn't see that. But it didn't resolve the error. It seems to be something in line 9 that it doesn't like.

avatar image btmedia14 MerlinsMaster · Jul 24, 2016 at 10:20 PM 0
Share

Yes, I should have noticed that! The error is related to the way a new element is created and assigned to the installSystem array. Declare the installSystem array outside the for loop and then elements of the array can be assigned inside the loop.

Lets assume the end point for the loop is the number of shipSystems. Then the assignment loop would look something like:

  public GameObject [] shipSystem;
  public Transform [] hardPoint;
  
 private GameObject[] installSystem;

  void Start ()
     {
        installSystem = new GameObject[shipSystem.Length];
        for (int i = 0; i < shipSystem.Length; i++)
           {
              installSystem[i] = (GameObject)GameObject.Instantiate(shipSystem[i]);
              installSystem [i].transform.parent = hardPoint[i].transform;
           }
     }
avatar image MerlinsMaster btmedia14 · Jul 25, 2016 at 01:08 AM 0
Share

Huzzah! It worked!

Thank you!

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

64 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

For loop comparing two different objects appears to not be running 1 Answer

Same for each loop with multiple arrays? 1 Answer

instantiate from two seperate values in for loop 1 Answer

Can't Locate gameobject in array 3 Answers

Inventory slots number are wrong 0 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