how to destroy a gameobject after some hits in unity 3d

Destroy(this.gameObject);

5
2

                                     public int hit = 0; public GameObject brickParticle; public AudioClip Brick_breaking; void OnCollisionEnter(Collision other) {     hit += 1; } void checkhit() {     if (hit == 2)     {         AudioSource.PlayClipAtPoint(Brick_breaking, transform.position);         Instantiate(brickParticle, transform.position, Quaternion.identity);         GM.instance.DestroyBrick();         Destroy(gameObject);     } }

5 (2 Votes)
0
4
5
Cyker 130 points

                                     void OnCollisionEnter(Collision other)  {      hit += 1;      checkhit();  }

4 (5 Votes)
0
4.25
4
Ishai Abrams 110 points

                                     public float RayLength;     public float Angle; // Ignore this     private bool MyBool;     public float SpeedRacer;     public float DragOn; // Ignore this public GameObject Bullet;    //Below this will create your raycast hit meaning if this hits something something else will happen.  RaycastHit hit;             //Ray creation             Debug.DrawRay(transform.position, Vector3.down);                Ray MyRay = new Ray(position this ray is initialized at, Vector3.whatever direction you want it pointing to);             if (!MyBool)             { //Creating the ray statement. //Making the ray attached to the object.     if (Physics.Raycast(MyRay, out hit,  RayLength)                    {                     if (your raycast variable.the collider of the object you wanna hit.its tag == "Your object you wanna destroy's tag")                     {                         //Put what ever you want to happen here for your case you want to destroy                              Destroy(Your game object you want hit)                           }                 }             }         }                                      }     

4.25 (4 Votes)
0
0
0

                                     void OnCollisionEnter(Collision YourGameobjectasAVarable) {   if(YourGameobjectasAVarable.collider.tag == "YourGameObject'sTag")         {             //Whatever you want to happen, in your case you want it to be destroyed             Destroy(//Your game object//*)         }

0
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
why does Destroy(gameObject); not work unity how to remove gameobject unity how to destroy gameobject in unity editor click to destroy gameobject unity how to destroy gameobjects after a certain time unity unity delete gameobject in script how to destroy gameobject on collision unity how to destroy one element in unity when a created a GameObject[] unity destroy a gameobject after certain time how to destory gameobject in unity unity spawn new objects on destroy Destroy game object unity example destroy gameobject in inspector unity scrip how to destroy unity unity should i be destroy gameobject how to destroy another game object in unity On GameObject destroy unity destroy gameobject from script unity 3d destroy object unity destroy(this) unity destroy this game object gameObject.remove unity how to delete gameobject unity c# unity c# remove gameobject how destroy the gameObject in unity destroy current gameobject unity destroyable gameobject unity unity destroy gameobject c\ how to delete gameobjects unity unity destroy gameobject from other classes destroy spwaned gameobject unity c# object destroy unity 3d when collide then gameobject destroy unity create and destroy game objects in game unity unity how to see destroy object how to destroy a gameobject in unity after time destroy gameobject unity c# How can I destroy my object in unity destroy specific gameobject unity this.gameobject.destroy how to destroy gameobject don't destroy objects in unity unity destroy gameobject in editor unity disable gameobject and destroy slowly destroy all objects with a script unity unity script to destroy game objects unity destroy all game objects how to destroy an object unity destroy a gameobject unity how to delete a gameobject in unity unity destroy scriptable gameobject destroy gameobject after time unity Unity delete gameobject in code how to destroy something unity how to instantiate an object and destroy it unity unity how to destroy obj functions used to destroy game ojects in unity3d how to destroy other gameobject unity destroy instance of object unity destroy(gameobject) can a gameobject destroy itself unity destroy.gameobject unity make object destroy itself destroy all gameobject unity unity find game object and destroy how to tell an object to destroy itself in unity .destroy unity unity destroy this how to delete gameobject in unity How to destroy an object unity c# destroy gameobject unity script destroy game object unity code Destroy GameObject in unity unity destroy gameobject not going away how to destroy a gameobject after time unity how to make an object destroy when hit by something unity unity destroy(gameobject) destroy objects in unity c# unity destroy current gameobject how to destroy object on unity gameobject destroy itself unity how does unity destroy work delete gameobject unity destroy an object in unity unity destroy other gameobject unity gameobject.destroy Destroy(GameObject); unity destroygameobject Destroy(gameObject); unity delete gameobject unity destroy colliding gameobject how to destroy current gameobject unity destroy.gamobject unity how to destroy an object in unity from another object unity destroy an object unity DestroyObject script unity destroy and object gameobject.destroy unity destroy gameobject immediately how to destroy a gameobject destroy this.gameobject how to destroy all the gameobjects in the scene unity unity how to delete gameobject how to destroy a gameobject after some hits in unity 3d destroy.this.gameobject unity destroy all gameobjects object.destroy unity destroy this unity unity destroy gameobject with script gameobject on destroy how to destroy game objects in unity unity despawn gameobject unity what gameobject is destroying this how to destroy the gameobject on which the script is in unity how to destroy game object fromscript unity destroy(this.gameObject, 5f); unity destroy after raycast destroy one destroy player on collision unity unity how to destroy and respawn object destroy other object unity unity destroy asset how to destroy gameobjects how to destroy an object on collision in unity destroy code in c# funtion destroy funtion c# remove gameobject in code unity Destroy(object); destroy mobjects unity object destroy gameobject .destroy unity unity Destroy(gameObject); Destroy Gameobjects in gameobject unity Destroy objects in gameobject unity destroy game object in unity 3d what happens when you destroy a gameobject unity how to destroy object unity DestroyObject unity Unity delet gameObject for unity destroy gameobject when looking at it unity api destroy prefab how to destroy game object unity object destruction unity how to destroy delete this game object unity are gameobjects destroyed when game is closed unity how to destory somthing unity destroy(this.gameobject) how to destroy gameobject from script unity delete object c# unity destroy gameobject Delete object unity c# Destroy unity document how to destory a gameObject unity how to break objects in unity c# how to destroy an object throught a script rigidbody component doesnt getting destroy in Destroy function unity how to destroy the current object delete gameobject unity script destroy self unity destroy.this unity destroy object in behavior How to destroy gameonkect unity delete self how to destroy the own object in unity destroy game object in unity unity c# destroy gameobject how to destroy object unit6y how to destroy something in unity how to destroy this? unity destroy function in unity how to destroy ob ject unity unity destroy script destroy in unituy how to Destroy yourself an item in unity in c# Unity destroy a object destrroy game object unity unity try destroy destroy objects in unity destroy game object gameobject destroy unity destroy an object destroy function unity unity Destroy() unity delete objects in update How to remove objects in Unity 2020 void destroy unity destroy in unity destroy Game Object unity3d unity player destroy unity destroy this.gameobject unity how to destroy the current game object script destroyed with object unity Unity how to destroy self scene self destruct unity kill gameobject unity how to destroy gameobject hot to destroy an element unity if destroy gameobject c# if destroy game object c# game object destroy unity destory object unity destroy method destory object unity unity detroy this game object destroy script c# unity how to destroy in unity remove gameobject unity unity c# delete gameobject unity remove objec unity dstroy how long does it take for game objects to be destroyed unity Destroy gameobjects in unity Destroy Script Unity C# destroy unity object unity gameobject delete gameobject destroy Object.Destroy(); unity unity remove gameobject how to destroy a 2d object with code in unity how to destroy an object in unity c# destroy script for c# delete gameobject unity c# unity how to destroy a gameobject unity how to destroy object destroy unity c# desDestroy(hit.collider); unity destory a gameobject through code unity this.destroy destroy gameobject c# unity how to destroy objects via scriptunity destroy gameobject script destroy() c# unity on gameobject killed unity how to kill a object how to delete object unity destroy gameobject destroy objects unity c# destroy game objects in c# delete self unity how to destroy self object in unity 2d hwo to delete a gameobject in unity how to destroy object in unity delete self c# unity Unity Destroy a scripts gameobject how to destroy gameobject in unity destroy gameobjec how to destroy objects ini unity unity destroy item unity gameobject destroy unity destory unity GameObject triggers unity c# destroy self unity destroying gameobjects destroy this.gameobject unity unity kill gameobject destroy game object unity unity destroy and place gameobject unity destroy a gameobject unity destroy an place gameobject Delete a game object unity destroy(this.gameobject) unity unity script destroy gameobject delete object unity unity destroy this gameobject destroying a gameobject unity how to destroy a gameobject in unity unity destroy self how to delete cube in script unity destroy object unity how to destroy an object in unity destroy an object unity how to delete an object through code in unity how to destroy objects in unity destroy gameobject associated with script c# destroy object unity unity destroy game object how to destroy the gameobject in unity unity destroy gameobject example destroying game objects in unity unity destroy object how to destroy a game object in unity how to destroy a gameobject in unity c# destroy this gameobject unity Destroy object in unity unity api how to destry objects gameobject destroy unity unity destroy gameobject how to destroy gameobject unity destroy unity unity destroy how to destroy self unity destroy gameobject unity
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source