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 hassy31 · May 13, 2015 at 10:56 AM · instantiatespritebounds

Instantiate a sprite inside bounds of other sprite?

I want to instantiate sprite inside bounds of custom shaped sprite(not box or circle). I tried using an "other" object and collider to check the "other" object positions are inside the bounds but it takes time and memory.so the game slows down. does anyone know a better way to solve this problem?

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

Answer by tebandesade · May 13, 2015 at 07:30 PM

Hi how are you? I don't know when you say "other" object you mean to not have a reference at all of the object, if you do, well you can calculate the bounds of the sprite by creating an empy game object and getting the coordinates where you want it to be instantiate it . Example . Get the start x point, get the end x point , Y start, Y end (all done manually by placing the empty game object you create it to check where these coordinates are in the world ) and later divide both end and start to get the center of the X and Y bound and use these in your new Vector3() you have to place in the instante function.

Otherwise, if you can reference, get the reference of the renderer of the sprite and later

 Bounds ti = Object.GetComponent<Renderer>().bounds;
 Vector3 ola = ti.center;
 Instantiate (test,  ola ,transform.rotation  );     

With this code, you'll get an object of the same size that always instantes itself.

Static Static

dynamic dynamic

Object being the object that has the bounds and test the prefab you're instantiating. Important things to take in to account, the object being instantated has to be the same or less size than the object that has the bounds, if not, you'll have to scale it.

More information regarding how to calculate bounds http://docs.unity3d.com/ScriptReference/Bounds.html


captura-de-pantalla-2015-05-13-a-las-22738-pm.png (20.1 kB)
captura-de-pantalla-2015-05-13-a-las-22726-pm-1.png (173.4 kB)
Comment
Add comment · 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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Instantiating prefabs within the MeshFilter volume of object 1 Answer

Instantiated Sprite is not rendering. 1 Answer

How can I detect non-rectangular bounds? 0 Answers

How do I get the bounds of a sprite on its sprite atlas? 0 Answers

Rotating a sprite toward the mouse position on instantiation. 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