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 Dave 11 · May 08, 2011 at 09:21 PM · arraysstringfunctions

String Arrays in a function

I'm not sure if I can explain this, but I need a function that does the following. Lets say I have a tilebased map like this:

01 02 03 04 05
06 07 08 09 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25

They're each a gameObject called platform1, platform2, platform3 etc... Now I want to let an explosion occur on each tile based on the input I give to the function. This I what I got

function Explode(platform : String) { parentObject = transform.Find(platform); var explosion : Transform; var detector : Transform; parentx = transform.Find(platform).position.x; parenty = transform.Find(platform).position.y; parentz = transform.Find(platform).position.z;

 explosion = Instantiate(explosionPrefab, Vector3(parentx,parenty+0.2,parentz), transform.Find(platform).rotation);
 explosion.parent = parentObject;
 detector = Instantiate(cDetectorPrefab, transform.Find(platform).position, transform.Find(platform).rotation);
 detector.parent = parentObject;
 yield WaitForSeconds(0.2);
 Destroy(gameObject.Find(platform+"/CollisionDetector(Clone)"));

}

But now I have to add lots of code like:

Explode("platform1");Explode("platform2");Explode("platform3");Explode("platform4");

that for 25 tiles and also 10 different combinations, so I need something like:

Explode( 01, 02, 03, 04, 05, 06, 07, x, 09, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 );

Explode( 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, x, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 );

and so on for each combination. This will clean up my code alot and it will make it easier to set each combination. :)

Does anyone know how to do this?

Thanks in Advance, Dave

Comment
Add comment · Show 9
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 Antony-Blackett · May 08, 2011 at 09:36 PM 0
Share

I'm not exactly sure what you're asking? Are you wanting to know if you can pass an arbitrary number of parameters to a function? If so look up the params keyword. void Explode( params string[] tiles){}

avatar image Joshua · May 08, 2011 at 09:41 PM 1
Share

http://unity3d.com/support/documentation/ScriptReference/Array.html read this. And for the explosions you can for instance do for(i=0;i

avatar image Joshua · May 08, 2011 at 10:05 PM 1
Share

Or have an array keeping track of which one to do and which ones not to do. Have as many entries in the array as you have platforms. Set them all to true. Set the ones with the same number as the platforms you don't want to explode to false and then use if(arrayName[i]).

avatar image Joshua · May 08, 2011 at 10:05 PM 2
Share

When coding for a large group of objects always try to use arrays and for loops ins$$anonymous$$d of doing each manually, that's just a waste of time.

avatar image DaveA · May 09, 2011 at 05:27 AM 1
Share

What ever happened to actually answering questions in the Answer box below?

Show more comments

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

No one has followed this question yet.

Related Questions

ios cant access variables in array 1 Answer

Array of Array 1 Answer

Issues with string array taken from a .txt file 2 Answers

Converting String Array to Int. 2 Answers

How to make certain elements in an array rarer when using random selection? 4 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