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 c0d3n4m3 · Sep 24, 2014 at 02:28 PM · texturedestroyraycasthit2dinput.mouseposition

On Click, have a texture/sprite appear where I clicked showing the score value for the object clicked on

Hi Guys/Gals,

I'm currently making a game that is simply a box, where fish spawn, and you have to click on the fish to Destroy() them, and you have 30 seconds to Destroy() as many fish as possible. Each fish has a point value; 1 point, 2 points, 3 points etc.

Now, I've got all the working code for knowing which fish has been clicked, and to Destroy() it once it's been clicked.

The trouble I'm having, is where to start with adding in something like the picture I quickly whipped up below:

 Please help! <3

I've never had to make something appear other than Instantiating a particle prefab at the point of click origin, so I really have no idea where to start with making something like the image's red spiky circle appear.

I have a feeling that it may have something to do with a GUIText/3D Text to show the fishes score value, but the image of the spiky circle (or whatever it may be, an image of a bubble would be more fitting) I have no idea how to implement, so I thought I'd ask the wonderful community on UA.

Here is the actual code snippet that destroys the fish:

 // Fish Destr0y Script
     if (Input.GetMouseButtonDown(0))
     {

         // Create the touch particle effect
         onTouchScore();

         // Print Score to 'totalScore' GUIText
         scoreText.guiText.text = totalScore.ToString();

         // Logging the Mouse Position to the console
         Debug.Log(Camera.main.ScreenPointToRay(Input.mousePosition));

         RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);

         // The actual destruction of the fish
         if (hit.collider.gameObject.name == "fish_red(Clone)")
         {
             Destroy(hit.collider.gameObject.gameObject);
             totalScore += 1;
             Debug.Log("<color=red>KILLED A RED FISH</color>");
         }
         else if (hit.collider.gameObject.name == "fish_orange(Clone)")
         {
             Destroy(hit.collider.gameObject.gameObject);
             totalScore += 2;
             Debug.Log("<color=red>KILLED A ORANGE FISH</color>");
         }
         else if (hit.collider.gameObject.name == "fish_green(Clone)")
         {
             Destroy(hit.collider.gameObject.gameObject);
             totalScore += 3;
             Debug.Log("<color=red>KILLED A GREEN FISH</color>");
         }
         else if (hit.collider.gameObject.name == "fish_blue(Clone)")
         {
             Destroy(hit.collider.gameObject.gameObject);
             totalScore += 4;
             Debug.Log("<color=red>KILLED A BLUE FISH</color>");
         }
         else if (hit.collider.gameObject.name == "fish_purple(Clone)")
         {
             Destroy(hit.collider.gameObject.gameObject);
             totalScore += 5;
             Debug.Log("<color=red>KILLED A PURPLE FISH</color>");
         }
         else if (hit.collider.gameObject == null)
         {
             Debug.Log("You hit NOTHING!");
         }

     }

I hope that I don't come across needy, but this is the first time I've actually got stuck in this mini-project and don't know where to turn!

All the best!

please_help.jpg (183.2 kB)
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 Baste · Sep 24, 2014 at 03:58 PM

A super-easy solution is to make a bunch of different prefabs for each possible score, and instantiate them at the position of the destroyed fish.

So you'd make a prefab with the red spikey circle, "+1" inside it, and then link it to your script with a public GameObject. Then, you'd modify your code like this:

 if (hit.collider.gameObject.name == "fish_red(Clone)")
 {
     Instantiate(onePointPrefab, hit.collider.gameObject.transform.position, Quaternion.identity);
     Destroy(hit.collider.gameObject.gameObject);
     totalScore += 1;
     Debug.Log("<color=red>KILLED A RED FISH</color>");
 }

Repeat for each possible score. You'll also want the Point prefabs to contain code that makes them go away after a while.

Comment
Add comment · Show 1 · 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 c0d3n4m3 · Sep 25, 2014 at 10:24 AM 0
Share

You sir, are legend!

This is perfect, and simple! Answer graciously accepted! Thank you ever so much. :)

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

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Unexpected problems with moving objects with a mouse click. 1 Answer

How do I get a texture2D snapshot from a single rendered GameObject/SpriteRender/MeshRender in a scene? 0 Answers

Assigning UV Map to model at runtime 0 Answers

How to destroy gameobjects with same tag using RaycastHit2D? 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