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

Explosion code bug!

Discussion in 'Scripting' started by Doomer022, Dec 9, 2018.

Thread Status:
Not open for further replies.
  1. Doomer022

    Doomer022

    Joined:
    May 16, 2018
    Posts:
    73
    Hello! I was in the process of making my game, and around 2 weeks ago, I spotted a bug I can't fix.

    In the game, you have explosive bullets, and when they contact with anything, they explode, and then they cant explode more than once. However, a bullet should only explode once, but sometimes they do something...weird. When the previously already exploded bullet has no contact with anything, and a new bullet gets fired, when the new one contacts with anything, the previous one explodes again, and the one you just fired does not!

    Code for firing the bullet:
    Code (CSharp):
    1. if (Input.GetMouseButton(0) && ammo > 0 && Time.time >= nextTimeToFire && bulletType == 2)
    2.         {
    3.             cam.transform.Rotate(0, recNum * Time.deltaTime, 0);
    4.             BulletPickUp.hasExploded = false;
    5.             nextTimeToFire = Time.time + 1f / fireRate;
    6.             grenadeInstance = Instantiate(grenade, gunEnd.position, gunEnd.rotation) as Rigidbody;
    7.             grenadeInstance.velocity = gunEnd.up * gunForce;
    8.             ammo--;
    9.             if (gunNum == 4)
    10.             {
    11.                 saglSFX.Play();
    12.             }
    13.             StartCoroutine("ShootAnimation");
    14.         }
    Code for picking up & exploding the bullet:
    Code (CSharp):
    1. if (GunFiring.bulletType == 2)
    2.         {
    3.             if (!hasExploded)
    4.             {
    5.                 Explode();
    6.                 GameObject explosionInstance;
    7.                 explosionInstance = Instantiate(explosionSource, gameObject.transform.position, gameObject.transform.rotation);
    8.                 hasExploded = true;
    9.             }
    10.  
    11.             if (col.gameObject.CompareTag("Player"))
    12.             {
    13.                 GunFiring.ammo += 1;
    14.                 GameObject pickUpInstance;
    15.                 pickUpInstance = Instantiate(pickUpSource, gameObject.transform.position, gameObject.transform.rotation) as GameObject;
    16.                 Destroy(gameObject);
    17.             }
    18.         }
    It would be nice if I didnt have to create 10 questions about the very same thing...
     
  2. Doomer022

    Doomer022

    Joined:
    May 16, 2018
    Posts:
    73
    Whatever, I'll try to fix it myself if literally, no one can help, or at least give some answers or tips...rubbish stuff
     
    nilsdr likes this.
  3. Did you just get upset because no one answered in the first 40 minutes on Sunday? :D LOL

    Edit: Oh, this is a duplicate. I see.
     
  4. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    That's two reports from different people about GV017 so I would recommend taking a break from forums and so on. Locking this.
     
Thread Status:
Not open for further replies.