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); } }
Thank you!
2
0
4
5
void OnCollisionEnter(Collision other) { hit += 1; checkhit(); }
Thank you!
5
0
4.25
4
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) } } } } }
Thank you!
4
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//*) }
Thank you!
0
0
Are there any code examples left?
New code examples in category C#
-
C# 2022-03-27 22:40:23 c# movement script
-
C# 2022-03-27 22:15:17 Delete last modification on EntityFramework Core
-
C# 2022-03-27 22:15:02 file.create folder c#
-
C# 2022-03-27 19:25:04 Error inflating class android.support.constraint.ConstraintLayout
-
C# 2022-03-27 19:15:02 top down shooting in unity 2D
-
C# 2022-03-27 18:50:02 c# remove invalid directory characters
-
C# 2022-03-27 18:30:07 how to use K2 games Games parallax background
-
C# 2022-03-27 18:25:10 c# replace crlf
-
C# 2022-03-27 18:25:09 keycode for left mouse click unity