Bullet destroy 2 game object intent one unity 2D

unity destroy gameobject
destroy gameobject in script
destroy gameobject with tag
unity destroy other gameobject
unity destroy gameobject with tag on collision
unity 2d destroy object
unity destroy not working
unity respawn destroyed object

When my bullet Collides with a Ball if there is 2 Balls at near or at the same position, all object get destroyed at same time. I set in my script when bullet collide with other then player it will be destroy.

I was trying to check every ball type with else if

 if(other.gameObject.tag == "yerrow")
    { 
        if (ballType >= 0 && ballType < 4)
        {

            clone1 = (GameObject)Instantiate(_ball, gameObject.transform.position, Quaternion.identity);
            clone1.gameObject.GetComponent<Balloon_Behave>().ballMove = -4;
            clone1.gameObject.GetComponent<Balloon_Behave>().transform.position = new Vector2(transform.position.x - Random.Range(0, 0.5f), transform.position.y - Random.Range(0,1));

            clone2 = Instantiate(_ball, gameObject.transform.position, Quaternion.identity);

            Destroy(this.gameObject);
        }
        else if (ballType == 4)
        {
            Destroy(this.gameObject);
        }
        Debug.Log("Yerrow COLl");
    }

Yerrow Script Destroy himself

  private void OnTriggerEnter2D(Collider2D other)
      {  
         if (other.gameObject.tag != "Player")
          {
             Destroy(this.gameObject);
             player.CanFire = true;
          }
      }

EDIT NOTE : Every ball collides with bulled is destroy intent one. I want to destroy one object by one bullet

You can combine these 2 functions, and use active flag to check the bullet status.

//Check if the bullet is active, then destroy the ball.
if(other.gameObject.tag == "yerrow" && other.gameObject.activeSelf)
{ 
    if (ballType >= 0 && ballType < 4)
    {
        ...
        Destroy(this.gameObject);
    }
    else if (ballType == 4)
    {
        Destroy(this.gameObject);
    }

    //Destroy and deactive the bullet here
    Destroy(other.gameObject);
    other.gameObject.SetActive(false);
}

Bullet destroy 2 game object intent one Unity 2D, Bullet destroy 2 game object intent one Unity 2D. When my bullet Collide with Ball if there is 2 Ball at near or same position all object destroy at� I know its probably something so small. I'm attempting to get on collision detect destroy "this" game object using the tag. The Bullet prefab has the Bullet tag and is spelt exactly the same, both gameObjects have both a rigidbody and a 2D box collider. Any help will be great.

On the ball, inside OnCollisionEnter2D

if(collision.collider.tag=="BulletTag")
{
     Destroy(collision.collider.gameObject);
     Destroy(gameObject);
}

Apply this onto the ball only.

Bullet destroy 2 game object intent one unity 2D, You can combine these 2 functions, and use active flag to check the bullet status. //Check if the bullet is active, then destroy the ball. if(other. Bullet destroy 2 game object intent one unity 2D. Discussion in '2D' started by theriyazsaifi_unity, Apr 17, 2019. theriyazsaifi_unity. Joined: Apr 1, 2019

Set bool to check ball bullet hit the ball or not and make it false if bullet collides with ball.

 public Player _player

 void start(){
 _powerUP = GameObject.Find("player").GetComponent<Player>();
 }

 if(other.gameObject.tag == "yerrow" && _player.canBe == true)
    {
        _player.canBe = false; // False just after hit
        if (ballType >= 0 && ballType < 4)
        {
            clone1 = (GameObject) Instantiate(_ball, gameObject.transform.position, Quaternion.identity);
            clone1.gameObject.GetComponent<Balloon_Behave>().ballMove = -4;
            clone1.gameObject.GetComponent<Balloon_Behave>().transform.position = new Vector2(transform.position.x - Random.Range(0, 1f), transform.position.y - Random.Range(0,1));
             Instantiate(_ball, gameObject.transform.position, Quaternion.identity);
            Destroy(this.gameObject);
        }
        else if(ballType == 4)
        {
            Destroy(this.gameObject);
        }  
    }

Don't true this value in Bullet On trigger, make it true when call Instantiate Clone, then it should work find.

unityscript, 2. OnTriggerEnter 's example in the documentation does exactly what you are asking for: using UnityEngine That script should be attached to the game object that is going to destroy stuff that touches it. I am making a 2D game, so you might need to adapt my code. 1 � Bullet destroy 2 game object intent one unity 2D� Creating and removing GameObjects in Unity happens all the time in just about every game, and so one of the first things a beginner programmer needs to learn is how to both Instantiate and Destroy GameObjects. The one process ties into the other, so we're going to approach this topic from the opposite end and look at Destroying a GameObject first.

How to Destroy Game Objects in Unity 3D, This tutorial covers how to destroy game object using the Destroy method. We will also give example of destroying game object on collision. If you try to explore the Destroy method in your IDE, you will see that the Destroy method has 2 In simpler terms, it means we're telling the script to destroy the bullet(fireball), since� How to use the Destroy() function to remove GameObjects and Components at runtime. This tutorial is included in the Beginner Scripting project. Previous: Linear Interpolation Next: GetButton and GetKey

50 Tips and Best Practices for Unity (2016 Edition), For 2D games that does not use lighting or physics, 1 Unity unit = 1 pixel (at " design" resolution) is usually good. You could use an empty game object, or even a singleton (see later or objects that are not Destroyed when a new scene is loaded. public void WindAttack() { /// behaviour Fire(bullets[2]); }. Unity 3D Detecting Object Collisions with onCollisionEnter. This tutorial covers creating a new Collider and attaching it to an object and capturing collisions using onCollisionEnter method and updating the counter. We will also learn about game tags and how to output message on Unity Console.

How to store references to scene objects in prefabs?, GameObject bullet = Instantiate(bulletPrefab, transform.position, transform. rotation); bullet. Unity does not allow you to reference scene objects to prefabs. So that we never lose a reference to this class in our Game. We have a AddToScore method which helps us keep track of points. To have this script run when our game runs we want to create another empty game object called GameManager. So go back to unity and right click in the hierarchy to create a empty game object.

Comments
  • It's probably because your bullet is too fast and before it detect the first collision it register another. What you could do is disable the collider when it collided with something, it should prevent firing twice
  • yerrow, bullet, ball, player, 4 types or just 2?
  • I just try to decrease speed too slow and try it. Result is same.
  • @shingo yerrow is tag of bullet, ball is target object its short by player
  • This is about c#, not unityscript.
  • Nothing changed still target more then one object