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 Apr 06, 2014 at 03:56 PM by MadJohny for the following reason:

Fixed

avatar image
-1
Question by MadJohny · Apr 06, 2014 at 03:23 PM · script errorjs-c#js - c#fixed array

Converting from js to c#

Hi, I have an old script that I want to convert to c#, but I'm getting errors, you can find the original script here: http://answers.unity3d.com/questions/423663/select-randomly-x-arrays-and-instantiate-them.html

I tried converting, this is what I have done so far, and now I don't know how to fix the errors it has.

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class BrickGenerator : MonoBehaviour {
 
     public int bricksToSpawn = 85;
     public GameObject[] bricks;
     List<GameObject> bricksListmeObject = new List<GameObject>(); // declare a new list
 
     void Start() {
         PopulateBricksList();
         ChooseRandomBricks();
     }
     
     
     void PopulateBricksList() {
         // declare a new list
         List<GameObject> bricksList = new List<GameObject>();
         
         // get the length of the built-in array
         int totalBricks = bricks.Length;
         
         // add each brick to the brickList
         for (int i = 0; i < totalBricks; i++){
             bricksList.Add(bricks[i]);
         }
     }
     
     
     void ChooseRandomBricks() {
         // choose a brick from the bricksList
         for (int i = 0; i < bricksToSpawn; i++ ){
             // find the current length of the bricksList
             int bricksRemaining = bricksList.Count;
             
             // get a random number
             int rndChoice = Random.Range(0, bricksRemaining - 1);
             
             // instantiate that chosen brick
             Instantiate(bricksList[rndChoice], brickList[rndChoice].transform.position, transform.rotation);
             
             // remove that brick from the list
             bricksList.RemoveAt(rndChoice);
         }
     }
 }

Here are the erros: https://www.dropbox.com/s/kboizlpgu3gas5v/Captura%20de%20tela%202014-04-06%2016.21.50.png

Thanks in advance.

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 Griffo · Apr 06, 2014 at 03:34 PM 0
Share

This may help you with the lists ..

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by getyour411 · Apr 06, 2014 at 03:31 PM

You declared bricksList inside PopulateBricks(), so it can only be called within that context; you could move it to the top/generic variable declare area.

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 getyour411 · Apr 06, 2014 at 03:38 PM 0
Share

move line 19 to 9

avatar image MadJohny · Apr 06, 2014 at 03:42 PM 0
Share

I think the script had an useless variable, I maybe fixed it now, I'll test it

Follow this Question

Answers Answers and Comments

22 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

Related Questions

Create a guitexture When clicked on 3d text? 0 Answers

js to C# converstion Problem 3 Answers

Convert js to C# Serializer problem 1 Answer

.js to C# conversion 4 Answers

How would i convert this from JS into C#? 2 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