Search Unity

I need help with being able to have more than one enemy in the game.

Discussion in 'Game Design' started by TheMonk123, Jan 14, 2021.

  1. TheMonk123

    TheMonk123

    Joined:
    Dec 18, 2020
    Posts:
    4
    I followed Brakeys RPG Tutorial and I tried adding two enemies in the game after finishing the series but when I attack the second enemy, the player attacks the other enemies health and when the other enemy dies and I keep attacking the second enemy, I get...
    MissingReferenceException: The object of type 'EnemyStats' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object.

    it then references me to the CharacterCombat script and the CharacterStats script.

    thank you for any help.
     
  2. Steve_Stevens

    Steve_Stevens

    Joined:
    May 3, 2016
    Posts:
    35
    You are going to have to post some code samples so we can see what's going on.
     
  3. yzRambler

    yzRambler

    Joined:
    Jan 24, 2019
    Posts:
    37
    One case possibly is the first enemy attacked has been deleted in default.
     
  4. TheMonk123

    TheMonk123

    Joined:
    Dec 18, 2020
    Posts:
    4
    it isn't just when the enemy dies, the health bar when I'm attacking the other enemy doesn't get effected but the first enemy's health bar does showing that the other enemy is getting attacked and loosing health... If you need to see the code, you can see it on brakeys Youtube channel with there rpg series the code is from because I believe it would be way more helpful as he explains the code.

    (I'm new at coding so sorry for my ignorance)
     
  5. TheMonk123

    TheMonk123

    Joined:
    Dec 18, 2020
    Posts:
    4
    Okay, no point posting anymore stuff, I figured out why it wasn't working and it had to do with a stamina bar script I added, I don't why this but I just stubbled across the solution.