Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Syndar · Jul 31, 2014 at 08:59 AM · gameobjectmouseclickonmousedownright click

Click for destroy Prefab, but sometime don't work

I have created an game for Windows 8.1, the gameplay is similar to an ant smasher, but with spaceships. You click on the spaceship for destroy it, but sometime the click don't work, if you click on the spaceship is not destroyed.

this is the part of the script who detect the click on the object:

 void OnMouseDown(){
     Destroy (this.gameObject);
     Instantiate(explosion, this.transform.position, this.transform.rotation);
     AddScore();
     AddCredits();
     }


the object is a prefab and this is the proprety: alt text alt text

Where i went wrong? Thanks for help.

bad clicking 1.jpg (238.4 kB)
bad clicking 2.jpg (224.0 kB)
Comment
Add comment · Show 6
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 Arcadewiz · Jul 31, 2014 at 09:30 AM 0
Share

Probably an issue with your spaceship colloder. Try using an encompassing box collider and check if your success rate increases or you can always try the alternate method of using raycast.

avatar image Syndar · Jul 31, 2014 at 10:21 AM 0
Share

how can set an encompassing box collider?

avatar image Arcadewiz · Jul 31, 2014 at 10:26 AM 0
Share

Just disable the collider on your spaceships and add a box collider with a size that covers your spaceship completely. Note: This is only to test whether the issue is due to the collider.

avatar image Syndar · Jul 31, 2014 at 12:29 PM 0
Share

I tried to enlarge the box collider at 1 for each axis at 1.5. The game has become much easier, but the problem is solved and I already have ideas to balance the difficulty.

avatar image Arcadewiz · Jul 31, 2014 at 12:31 PM 0
Share

If this has solved your problem please mark it as solved and close it. Have a nice day

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by SkandYxyz · Jan 07, 2021 at 12:54 PM

Hi,

i guess you first need to instantiate the prefabs and then you can destroy it with this script.

 public class DestroyPlayAudio : MonoBehaviour
     {
         public AudioSource audioSource;
         public AudioClip clip;
         public float volume=0.5f;
     
         void Update()
         {
              if (Input.GetButtonDown ("0")) 
             {
                 Raycast ray=Camera.main.ScreenPointToRay(Input.mousePosition);
                 Raycasthit hit;
                 if (Physics.Raycast(ray, out hit))
                 {
                     Destroy(hit.collider.gameObject);
                     audioSource.PlayOneShot(clip, volume);
                 }  
             }
         }
     }

Insert your audiofile in the variable slot in the Monobehaviour.

If you want to create games fast without coding learn and use Playmaker or Game Creator.

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

24 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 avatar image

Related Questions

Reference creator of gameObject 1 Answer

How do I make a game object spawn and then stay and move up when mouse is cilcked? 1 Answer

how to call a gameobject in one function(mouse selection) to another function (GUI) 1 Answer

Change Mesh/Gameobject onmousedown?,Swap mesh/gameobject randomly onmousedown 0 Answers

Open and close UI Menu on background mouse click 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