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 MatthewFunctions · Jun 23, 2013 at 12:39 AM · movementobjectmousedragclick

OnMouseUp() Click Display Effect.

Hi,

I was wondering how would I go about displaying an object, or a particle effect every time I OnMouseUp() click on the terrain. Similar to a RTS game. When you click on the destination, a particle or object is displayed showing where your destination is. Thank you very much.

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
Best Answer

Answer by markpdolby · Jun 28, 2013 at 09:15 AM

I would suggest using a ray cast from the mouse position onto the terrain:

 [SerializeField] private ParticleSystem effect;
 
 void Update(){
 Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
 RaycastHit hit;
 if(Physics.Raycast(ray, out hit, 100, LayerMask.NameToLayer("Terrain")))
 {
     effect.transform.postion = hit.point;
     effect.Play();
 }
 }
Comment
Add comment · Show 9 · 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 MatthewFunctions · Jun 28, 2013 at 09:30 AM 0
Share

Thank you for your response. I am still getting used to coding. Should I declare a variable for it? Where should I add the particle? I can not seem to get it to work in Javascript or C#. I am really sorry if this question has an obvious answer.

avatar image markpdolby · Jun 28, 2013 at 09:36 AM 0
Share

Sorry it was a bit pseudo code, I've edited my answer so see if that works now. So in your scene attach the script to the main camera for example and create a particle system as a seperate object. On the script then drag the particle system object onto the effect slot in the inspector. This is assu$$anonymous$$g you are using Unity 4.

avatar image MatthewFunctions · Jun 28, 2013 at 09:44 AM 0
Share

That is okay, I really appreciate your help. I am getting this error now.

Assets/ParticleSystem.cs(16,20): error CS1061: Type ParticleSystem' does not contain a definition for Play' and no extension method Play' of type ParticleSystem' could be found (are you missing a using directive or an assembly reference?)

avatar image markpdolby · Jun 28, 2013 at 09:48 AM 0
Share

You need to name your script with a different name as Unity already uses the name ParticleSystem. So rename your script to something like $$anonymous$$ouseControls

avatar image MatthewFunctions · Jun 28, 2013 at 10:00 AM 0
Share

I think it may be me. I can not get it to work for some reason. I added the particle as a GameObject and attached it to the script that is attached to the camera. I click and it does not appear where I click, or at all (only the original one shows). Your help is very clear, I must be doing something wrong.

Show more comments

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

16 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

Related Questions

Dragging movement Speed 1 Answer

Object Movement via Mouse Click? 3 Answers

Click and Drag Camera 3 Answers

Object menu must be at the center of the object 1 Answer

How to disable button OnClick when drag on the screen with OnMouseDrag 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