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 Qo2770 · Jul 19, 2014 at 10:17 AM · spritedestroylocationsquare

Destroying a square of sprites at specific coordinates

Hello, I am working a medium 2d mining game and I have a script that makes a custom-sized square world, but I would like to clear a square in the middle and clear spaces for random ores with only the coordinates and thae name of the object. I now that there is a way to delete a GameObject at a specific location but it is far too big to be used when deleting multiple objects. Here is my function for creating the square world:

 function MakeRock() {
         Instantiate(Rock, Vector2(0, 0), Quaternion.identity);
         Instantiate(Ground, Vector3(0, 0, 0.1), Quaternion.identity);
             
     while (-FillUp * 2 <= Size) {
         while (up < Size) {
             Instantiate(Rock, Vector2(FillUp, CountUp), Quaternion.identity);
             Instantiate(Ground, Vector3(FillUp, CountUp, 0.1), Quaternion.identity);
             CountUp = CountUp + 0.5;
             up++;
         }
         FillUp = FillUp - 0.5;
         up = 0;
         CountUp = 0.5;
     }
     
     while (FillDown * 2 <= Size) {
         while (down < Size) {
             Instantiate(Rock, Vector2(FillDown, CountDown), Quaternion.identity);
             Instantiate(Ground, Vector3(FillDown, CountDown, 0.1), Quaternion.identity);    
             CountDown = CountDown - 0.5;
             down++;
         }
         FillDown = FillDown + 0.5;
         down = 0;
         CountDown = -0.5;
     }
     
     while (FillRight * 2 <= Size) {
         while (Right < Size) {
             Instantiate(Rock, Vector2(CountRight, FillRight), Quaternion.identity);
             Instantiate(Ground, Vector3(CountRight, FillRight, 0.1), Quaternion.identity);
             CountRight = CountRight + 0.5;
             Right++;
         }
         FillRight = FillRight + 0.5;
         Right = 0;
         CountRight = 0.5;
     }
     
     while (-FillLeft * 2 <= Size) {
         while (Left < Size) {
             Instantiate(Rock, Vector2(CountLeft, FillLeft), Quaternion.identity);
             Instantiate(Ground, Vector3(CountLeft, FillLeft, 0.1), Quaternion.identity);
             CountLeft = CountLeft - 0.5;
             Left++;
 
         }
         FillLeft = FillLeft - 0.5;
         Left = 0;
         CountLeft = -0.5;
     }
 }
 


Thank you, Qo2770

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 Bojidar · Jul 22, 2014 at 05:20 PM 0
Share

Try storing your sprites in a three-dimensional Array (e.g. Generic List), if you are using voxels like $$anonymous$$C. If you are not, then you might think of some structure like an Oct-tree, or use a Hash$$anonymous$$ap(e.g. Dictionary) based on the position of your GameObjects.

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

23 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

Related Questions

Trigger Animation doesn't work, please help me. 1 Answer

I can get a sprite to look at my mouse but not another Vector3, im not doing anything wrong but the sprite just looks in one direction. 1 Answer

Does destroying a Sprite also destroy it's texture? 1 Answer

Objects Living Sprite when destroyed 1 Answer

How to apply OnMouseDown on sprites according to z position... 3 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