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

Question Enemy spawn not working (Uses prefab)

Discussion in 'Prefabs' started by Ghost0fHerobrine, Mar 10, 2023.

  1. Ghost0fHerobrine

    Ghost0fHerobrine

    Joined:
    Oct 16, 2022
    Posts:
    7
    I'm making a game and want it to spawn in Enemies now and then, I got the spawning to work, but the spawned-in versions are a little glitched. What's supposed to happen is that the enemy chases the player (check, that works), then once it gets close, it attacks and gets rid of hp, the attack part is the one not working, in simple terms, everything except the attack works because the script from the PLAYER prefab won't work since the player in the scene is apparently different? I don't know it's confusing. Really confusing to me at least, so please help if you know the solution.

    TL;DR: I want enemies to spawn in, but when they spawn in, the attack function doesn't work because the enemy prefab I made is linked to the player prefab's script, but it's not working even though it's supposed to.

    Here's a few pictures to show it with images, not confusing words.
    Enemy picture thingy something is wrong one.png Enemy picture thingy something is wrong two.png
     
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,294
    Your code is not compiling, so nothing is going to work before you fix that.
     
  3. Ghost0fHerobrine

    Ghost0fHerobrine

    Joined:
    Oct 16, 2022
    Posts:
    7
    What do you mean by compiled?
     
  4. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,294
    upload_2023-3-11_15-9-54.png

    When your code has errors, none of it works. So you have to figure out how to resolve those before making any changes has any effect.
     
  5. Ghost0fHerobrine

    Ghost0fHerobrine

    Joined:
    Oct 16, 2022
    Posts:
    7
    ohhhh no that was separate, it's not that, I got rid of the lines that weren't working for a while and it still doesn't work.
     
  6. Ghost0fHerobrine

    Ghost0fHerobrine

    Joined:
    Oct 16, 2022
    Posts:
    7
    @Baste I fixed that, that wasn't problem, it still doesn't work.