how to destroy a gameobject after some hits in unity 3d
C#
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//*) } void OnCollisionEnter(Collision other) { hit += 1; checkhit(); } 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) } } } } } 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); } }
Also in C#:
- Title
- while loop c#
- Category
- C#
- Title
- iterate through xpdictionary devexpress
- Category
- C#
- Title
- C# array to string
- Category
- C#
- Title
- countdown script unity
- Category
- C#
- Title
- c# get list of all class fields
- Category
- C#
- Title
- idbset sqlquery
- Category
- C#
- Title
- convert string to decimal c#
- Category
- C#
- Title
- datatable return column names
- Category
- C#
- Title
- public enum c#
- Category
- C#
- Title
- c# inotifypropertychanged best practices
- Category
- C#
- Title
- How to set an expiry date on a program
- Category
- C#
- Title
- how to get the last element in an array in c#
- Category
- C#
- Title
- unity 2d Drag object
- Category
- C#
- Title
- check if number is even or odd c#
- Category
- C#
- Title
- resize image c#
- Category
- C#
- Title
- c# keyvaluepair
- Category
- C#
- Title
- configure 1 to 1 relation ef
- Category
- C#
- Title
- c# remove last value from list
- Category
- C#
- Title
- C# invoke
- Category
- C#
- Title
- csharp datetime string format
- Category
- C#
- Title
- how to find the type of a object c#
- Category
- C#
- Title
- c# repeat string x times
- Category
- C#
- Title
- vb.net drag window without titlebar
- Category
- C#
- Title
- how to create a variable in C#
- Category
- C#
- Title
- what is the namespace for textmesh pro
- Category
- C#
- Title
- unity button interactable
- Category
- C#
- Title
- unity key detection
- Category
- C#
- Title
- define enum c#
- Category
- C#
- Title
- nunit return parameter
- Category
- C#
- Title
- how to add object in dictionary in c#
- Category
- C#
- Title
- instantiate object in circle
- Category
- C#
- Title
- can send but cannot receive email dreamhost email
- Category
- C#
- Title
- cursorlockmode cannot be used as a method C#
- Category
- C#
- Title
- how do i limit the amount of prefabs in unity using c# script
- Category
- C#
- Title
- c# how to exit program
- Category
- C#
- Title
- How to get number of months between 2 dates c#
- Category
- C#
- Title
- c# check if string is all numbers
- Category
- C#
- Title
- perlin noise unity
- Category
- C#
- Title
- asp.net core mvc not triggering client side validation
- Category
- C#
- Title
- iframe set html content c#
- Category
- C#
- Title
- create line in unity
- Category
- C#
- Title
- c sharp if string equals
- Category
- C#
- Title
- autoresetevent
- Category
- C#
- Title
- how to detected WindowCloseEvent in other window wpf
- Category
- C#
- Title
- whats a string
- Category
- C#
- Title
- how to generate random unique id in c#
- Category
- C#
- Title
- fly cam extended script unity 3d
- Category
- C#
- Title
- nullreferenceexception c#
- Category
- C#
- Title
- unity list
- Category
- C#
- Title
- value is null to insert in c#
- Category
- C#
- Title
- c# creating exceptions
- Category
- C#
- Title
- c# split a string and return list
- Category
- C#
- Title
- built in methods to order a list c#
- Category
- C#
- Title
- C# Cast double to float
- Category
- C#
- Title
- c# delegate return value invoke
- Category
- C#
- Title
- c# code snippet template
- Category
- C#
- Title
- how to get length of okobjectresult c#
- Category
- C#
- Title
- animations for pause menu
- Category
- C#
- Title
- drag object unity 2d
- Category
- C#
- Title
- how to access first child of parent unity
- Category
- C#
- Title
- c# fold list
- Category
- C#
- Title
- blazor onchange event not firing with inputselect
- Category
- C#
- Title
- c# inline initialize dictionary
- Category
- C#
- Title
- set object to random color unity
- Category
- C#
- Title
- c# relaxed boolean cast
- Category
- C#
- Title
- c# replace string case insensitive
- Category
- C#
- Title
- what type of variable is true or false in c#
- Category
- C#
- Title
- c# reverse list
- Category
- C#
- Title
- isdaylightsavingtime in c#
- Category
- C#
- Title
- c# update control from another thread
- Category
- C#
- Title
- c# clear console read chache
- Category
- C#
- Title
- image filter
- Category
- C#
- Title
- unity material offset script
- Category
- C#
- Title
- orderby make sunday last day c#
- Category
- C#
- Title
- copy to clipboard unbity
- Category
- C#
- Title
- xamarin forms alarm
- Category
- C#
- Title
- c# anonymous class
- Category
- C#
- Title
- c# get current directory xamarin
- Category
- C#
- Title
- zoom gedit
- Category
- C#
- Title
- mvc input type file
- Category
- C#
- Title
- c# print expression tree
- Category
- C#
- Title
- how to deactivate objects through scripts in unity
- Category
- C#
- Title
- divide string in chunks c#
- Category
- C#
- Title
- c# distinct comparer multiple properties
- Category
- C#
- Title
- eventos c#
- Category
- C#
- Title
- center an image horizontally and vertically
- Category
- C#
- Title
- c# download file
- Category
- C#
- Title
- uwp file open picker
- Category
- C#
- Title
- c# iterate over string
- Category
- C#
- Title
- compile in one single exe c#
- Category
- C#
- Title
- install .net sdk ubuntu 20
- Category
- C#
- Title
- take screenshot in c#
- Category
- C#
- Title
- unity serializefield
- Category
- C#
- Title
- c# bitmap to array byte
- Category
- C#
- Title
- c# datafield change cell background color
- Category
- C#
- Title
- void start
- Category
- C#
- Title
- c# loop through repeater items
- Category
- C#
- Title
- how to parse a string to an integer c#
- Category
- C#
- Title
- unity monobehaviour
- Category
- C#
- Title
- using in c#
- Category
- C#