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 post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by slehmann101 · Jul 08, 2014 at 08:06 AM · guiinstantiateparticlesparticlesystemcoordinates

Generating a particle effect on top of a GUIElement

I have a number of guitextures which are hearts in order to create a sort of life meter. I would like when the player loses a heart for the heart to change into a skull in a puff of smoke. I currently have the hearts correctly turning into skulls, and a puff of smoke is generated, however the smoke is created in the wrong location.

The smoke is currently generated by:

 GameObject smokeObj = (GameObject)Instantiate (smoke, transform.TransformPoint(transform.position), Quaternion.identity);

I have also tried:

  GameObject smokeObj = (GameObject)Instantiate (smoke, transform.position, Quaternion.identity);

I know that the reason that the smoke is created in to wrong location is due to GUIElements using a different coordinate system than other gameObjects.

How can I create the smoke in the correct location?

This is a 2D project and I am currently using Unity 4.5of6, with windows 8.1.

Thank you for your assistance, if you have any questions please do not hesitate to ask.

Comment
Add comment · Show 2
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 meat5000 ♦ · Jul 08, 2014 at 01:02 AM 0
Share

You don't want just transform.position?

avatar image slehmann101 · Jul 08, 2014 at 04:02 AM 0
Share

That does not work either, i tried it before this, sorry should have mentioned that.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by rutter · Jul 08, 2014 at 08:05 AM

The camera class has a bunch of helper functions for translating points to/from "screen points" (in pixels) and "viewport points" (which GUITextures use) and "world points" (in the scene itself).

In particular, it sounds like you might want ViewportToWorldPoint. Be careful to set a z-component for your input, which represents the desired distance away from the camera.

When in doubt, Camera.main is usually the player's main camera.

Something like this:

 Vector3 worldPos = Camera.main.ViewportToWorldPoint(SOME_GUI_POSITION + Vector3.forward); 
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 Owen-Reynolds · Jul 08, 2014 at 02:55 PM 0
Share

...and this is the "GUIElements using a different coordinate system" mentioned by the OP.

Clearly, you have to translate GUI coords to regular coords, and this is what does it.

avatar image slehmann101 · Jul 09, 2014 at 02:47 AM 0
Share

This seems to spawn it in the wrong position, not where the GUI is located... $$anonymous$$y code is as follows:

 Vector3 worldPos = cam.ViewportToWorldPoint(transform.localPosition + Vector3.forward); 
         worldPos.z=0;
         GameObject smokeObj = (GameObject)Instantiate (smoke, worldPos, Quaternion.identity);
         Debug.Log(worldPos);
                 //smokeObj.layer = 5;
                 smokeObj.transform.parent = this.transform;


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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Syncing particle system in Photon Unity Networking 1 Answer

How to Instantiate gameObject where a particle dies 2 Answers

How to put a particle system on each of Text Mesh Pro characters? 0 Answers

Best way to spread particle system? 1 Answer

How do I make instantiated particles inherit Transform movement from their parent object? 1 Answer


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