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

Multiple enemies.

Discussion in 'Scripting' started by willeh1998, Sep 28, 2016.

  1. willeh1998

    willeh1998

    Joined:
    Sep 28, 2016
    Posts:
    4
    Ok so i have 1 enemie in my game so far, but when i add another one with the same script when i hit enemy nr 1, enemy 2 takes dmg. and when enemy 2 dies the game crashes because it cant find an enemy with the tag "enemy"




    Enemy script-----------------------------------------------------------------------------------------------------------------



    Attack script-----------------------------------------------------------------------------------------------------------------

     
  2. CrymX

    CrymX

    Joined:
    Feb 16, 2015
    Posts:
    179
    follow = GameObject.FindGameObjectWithTag("Enemy").GetComponent<follow>();

    this is wrong, because you have 2 Enemy, you can call this function 10 times and 10 times it's going to return the first enemy in the scene
     
  3. willeh1998

    willeh1998

    Joined:
    Sep 28, 2016
    Posts:
    4
    Ye that is what i was thinking. Any ideas of fixing it?
     
  4. willeh1998

    willeh1998

    Joined:
    Sep 28, 2016
    Posts:
    4
    I want it to be. If anything with the tag "enemy" gets hit by player. Take 1 dmg from player
     
  5. willeh1998

    willeh1998

    Joined:
    Sep 28, 2016
    Posts:
    4
    Nevermind fixed it with
     
    CrymX likes this.