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
1
Question by alpayoguz97 · Nov 19, 2020 at 02:32 PM · collisionunity 2dcollidersdestroy objecttriggering animation box collider

Destroy Clone Game Object On Collision Doesn't work

Hey Guys,

I'm trying to make Block Breaker game. Now, I'm trying to create random power ups as a chance %5 when a block is destroyed.


This is where I instantiate a game object randomly.

 public class BlockSquare : MonoBehaviour
 {
 [SerializeField] GameObject specPow;
  public GameObject spcPow;
 
 public void SpecPowInstantiate()
     {
         int randomNum = UnityEngine.Random.Range(0,20 );
         if(randomNum == 10)
         {
             spcPow = Instantiate(specPow, transform.position, transform.rotation) as GameObject;
             Destroy(spcPow, 5f);
         }
         
 
     }
 
 
 
 }


This is where I tried to destroy clone gameobjects. But I couldnt :

 public class Paddle : MonoBehaviour
 {
    BlockSquare blckSpecPow;
 
    private void OnTriggerEnter2D(Collider2D collision)
     {
         if(gameObject.tag == "SpecPowGameObject")
         {
             Destroy(blckSpecPow.spcPow);
         }
 
         
     }
 }
 
 
 


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

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by GGfazo · Nov 19, 2020 at 03:00 PM

I think the problem is in the second script, in the part where it says , because it should be like this cause this way it will search if the other objects tag is that and no the object tag of the script. If that doesn't work maybe the problem could be in the collider, rigidbidy or the Triggered option. But i think is the first thing.

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 alpayoguz97 · Nov 19, 2020 at 03:08 PM 0
Share

Sorry but I didn't understand what you meant. Could you explain clearly pls ?

avatar image GGfazo · Nov 19, 2020 at 03:11 PM 1
Share

sorry the Important part of the message get erased for some reason I'll explain it. Where it says gameObject.tag == "SpecPowGameObject" it should be other.gameObject.tag == "SpecPowGameObject" because this way will comprove the other object tag and not hte tag of the gameobject that is "holding" the script.

avatar image
0

Answer by alpayoguz97 · Nov 19, 2020 at 03:28 PM

I tried what you said. But that didn't change anything. Thanks for your answer. Any other thoughts ?

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 GGfazo · Nov 19, 2020 at 03:52 PM 1
Share

I suggest to change directly Destroy(blckSpecPow.spcPow) for Destroy(GameObject.FindWithTag("SpecPowGameObject")) and then comprove it works

avatar image alpayoguz97 GGfazo · Nov 19, 2020 at 04:12 PM 0
Share

Omg. Sorry but when I tried what you said above again, it fixed.

Thanks for your interest. I was trying to fix this since this morning.... (about 8 hours). Really thanks again !

avatar image
0

Answer by logicandchaos · Nov 19, 2020 at 04:04 PM

Check that your tag is correct on your gameObject.

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

216 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 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 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 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 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 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 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 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 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

How to optimize a lot of colliders? 1 Answer

Ghost collisions problem: RigidBody player bounces, when moving on platform edges 2 Answers

PolygonCollider2d Use Z Axis 0 Answers

Coin collecting with prefabs 2 Answers

Smooth movement for the block upon player collision,Smooth box movement 0 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