• 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 mealone · Mar 10, 2014 at 05:44 AM · instantiateprefabdestroytouches

when prefabs are spawned I want to touch them to destroy. help?

the issue I am having is this- when I touch the spawned game object it gets destroyed, but I want it to spawn another sprite before it it destroyed when the raycast2d hits it. I tried send message, but because it is an instantiated prefab this method did not work and returned an error in the console. What I am trying to do in pseudo code is this. Green balloon is spawned, when touch/click is pressed, green balloon spawns green balloon popped sprite and the green balloon is destroyed. So when touch is pressed on game object, spawn prefab at the same location and destroy the game object which is touched. I'm sorry if this is a really simple process, but I'm not sure how to get this to work given I am new. Thanks in advance for any further help regarding the solution.

Comment
Add comment · Show 3
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 getyour411 · Mar 10, 2014 at 06:06 AM 0
Share

Is the code that manages the raycast on the Green balloon, or one some other script like playerInput, etc.?

avatar image kestik · Mar 10, 2014 at 06:17 AM 1
Share

Call 'Instantiate' method for popped sprite before calling 'Destroy' on green baloon sprite. Instantiate(poppedBaloon, transform.position, trasform.rotation); Destroy();

avatar image mealone · Mar 10, 2014 at 03:01 PM 0
Share

i have this code on the main camera in the scene, when i touch/click the balloon it gets destroyed, but maybe i did it wrongly? i'm really not sure because I want that when i touch the balloons they get destroyed but instantiate the balloon pop sprite before being destroyed in the same location that the balloon was.

function Update () {

      if (Input.Get$$anonymous$$ouseButtonDown(0))
      {
        
        var hitm : RaycastHit2D = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
        if(hitm.collider != null)
        {
          Destroy (hitm.collider.gameObject);
        }
        if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began){
        if(hitm.collider != null)
        {
          Destroy (hitm.collider.gameObject);
        }
      }
 }
 }

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

21 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

Related Questions

Deleting a GameObject 2 Answers

How to destroy a instantiated buton ? 2 Answers

My prefab isn't getting destroyed 1 Answer

Solved: Destroy command not working 1 Answer

Parenting an instantiated prefab. 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