Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

how to destory the gameobject (enemy) if the player has shot two fire shot using c# in unity5

Discussion in 'Scripting' started by Linus392, May 29, 2015.

  1. Linus392

    Linus392

    Joined:
    Aug 14, 2013
    Posts:
    24
    am getting the problem while destorying the enmy when the player has fire two fire shot. my code is
    if (other.gameObject.tag == "Bomb")
    {

    test=test+1;

    Debug.Log ("The Bullet has hit the Bomb");

    }

    else if (other.gameObject.tag == "Bomb"&& checkpoint==2 )
    {
    Destroy (other.gameObject);
    //checkpoint = 0;
    Debug.Log ("The Bullet has Destroyed the Bomb");
    }
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    [ code] [ /code] tags when you paste code into the forums really help with the formatting (sticky at the top of the scripting section about that)

    you appear to be counting the hits with "test" but you use "checkpoint" in the elseif.... ?

    would probably make more sense to have a script on the "bomb" which just counted how many times it had been hit and handles what the bomb needs to do when it is "destroyed" rather than trying to work this from what looks to be the projectile side of things.