Survival Shooter Tutorial – 9 of 10 : Spawning Enemies – Unity Official Tutorials (new)

As I’ve just said we’ve just created one enemy. What we didn’t want to force you guys to do was to repeat those steps again to make a fairly identical enemy. Instead what we want to do is show you how you can use some of the things that you’ve just done such as the animator controller, for example, and reuse that on a new enemy. So what we did was we have very kindly gone and created for you the Zombear. A new enemy who is otherwise pretty identical to the Zombunny. He looks like this. What we’re going to do is to assign certain things to that Zombear to make him work very much in the same way as the Zombunny. So the great thing about the Unity animator system is that it’s reusable, so these are states that have animation clips assigned to them. So when we look at the animator for our EnemyAC, there it is, we have a bunch of different states. We have Move, Idle and Death. Now these states aren’t the clips themselves, they are holders for clips. So those animations are setup in there and if you’ve got something that has a similar skeleton, like our Zombunny and Zombear do, we can reuse the state machine and reuse both the script that talks to these parameters and the parameters themselves. In order to drive a different enemy. So in the prefabs, with my Zombear selected, what I’m going to do is click on my animation folder and then drag and drop EnemyAC on to the animator controller property. So I’m dropping it on to this. Currently it says None. So we made EnemyAC earlier for the other character, we’re reusing it here so it will work in exactly the same way. You will also notice it’s got the same scripts applied to it, it’s got EnemyAttack, Health and Movement, which are looking for this animator controller and looking for the parameters that we setup. So that’s just going to work right off the bat. Then the third enemy is our Hellephant. He rather shockingly looks like this. The difference with this guy is that he’s not the same type of enemy. He’s a different shape and his rig’s different and his animations are different. However he does the same things. He has Move, he Idles and he has Death. But they’re not the same animation clips. So one way to approach this would be to make a brand new animator controller. Make the transitions. Make new parameters for it and set it up in a fairly similar way. Also in the operating system you’ve got Copy/Paste to create a copy of it. Again it’s redundant and completely unnecessary. Yeah, so, we don’t want to do this. So there’s the new feature, fairly recently added called Animator Override Controllers. What this means is you can create lots of different classes of characters in your game. And if, for example, they all share a similar skeleton you can have the same state machine driving all of them but just change the animation clip that it uses. So we’re going to create that asset. So if you click on the animation folder in your project. Then go to Create you will see something called Animator Override Controller. Click on this and we’re going to call this HellephantAOC, Animator Override Controller. You’ll notice that the icon is a little different from the others, the others have three squares and a play icon, this has a + icon. Because it’s effectively taking the same state machine and adding over the top the ability to use different clips within the states. So one example for this could be that you have a character that runs a certain way and jumps a certain way but when he shoots or when he attacks it’s totally different. so you use the same animator controller to drive the running and the jumping etcetera but then you just override the attack. So we’re going to override all three simply because we’re reusing the same parameters and the same transitions. The way that we use this is that we select the asset in the project panel like it is now and we give it a controller to relate to, so we drag and drop EnemyAC on to the Controller slot at the top of the inspector. So what this does is it goes through and says ‘what states does this animator controller have?’ and it’s found Move, Idle and Death. Then we have the ability to fill in new animation clips to replace the ones that are in those existing states So the animations, just like before, are within the character folder. Just a word of warning here, what we don’t want to do is click off Hellephant. So I’m going to click on Characters and I’m going to click on the arrow for Hellephant, I’m not going to select it because we don’t want the inspector to start showing something else. We could lock the inspector but I’m not going to do that. So I’m going to go and drag Move on to the Move slot. and I’m going to drag Idle on to Idle and Death on to Death. So effectively we’ve got the same states, the same state machine, the same logic for how he’s going to behave, but the animation clips within each state are being overridden or replaced by these animation clips from the model. So the animation for that character was done within that model. The rig doesn’t have to be shared, but we can replace the animation with whatever we need. So the last step then is to go to our prefab of the Hellephant with all of the scripts setup and just instead of dragging on the EnemyAC we’re going to drag on the override controller in to the Animator slot. HellephantAOC in there. So now we have three enemies that are setup and ready to be spawned in to our game. We need some kind of manager object. So much like our ScoreManager or anything else we want to have an individual object that is in charge of the spawning of the enemies, how frequent it is, etcetera. So we like to keep things neat here so we’re going to create a brand new object to manage this on. You could, like any script you can attach this to any object you want to. You could attach it to the environment, you could attach it to the camera or anything you expect to stay in the game, but we’re not going to, we’re going to create an empty game object. There’s not really any overhead or any problem doing it this way and it allows us to keep things modular and separate. The great thing about this of course is if we wanted to make this a prefab we could drop this in to another level and reuse it. So I’m going to go to the hierarchy this time and go to Create – Empty And create an empty game object. I’m going to rename this EnemyManager. It’s a good habit to get in to when creating a new game object, empty game object, whatever, to ensure that it’s at (0, 0, 0) it’s at the origin, just in case you might be using it as a container for other things and you don’t want it to change the co-ordinates of child objects. But it’s one of those things that might save you some confusion later when you’re wondering why things are moving around and and that’s why. So just something to keep in mind, it’s a good habit to do. So I’ve reset the position to (0, 0, 0). Then, very kindly we’ve prepared a script that will do this for you. In the Scripts folder under Managers you will find EnemyManager and you can simply drag and drop onto the EnemyManager. So just to show you one other way of assigning a script. You can either drop it on to the name in the hierarchy, you can also drop it on to empty space in the list of components in the inspector. So I’m going to double click the name of that script to open it. This is quite a simple script this one. It’s got a bunch of public variables that need assigning so because this script is something we’re going to use several times and assign different enemies, different spawn points to we’re not going to want to use the script to find those, we’re going to want to use the editor to drag and drop all of these things. That’s exactly what we’re going to do, so you see a lot of public variables up front. The first thing if a reference to the PlayerHealth. We’re going to want to check we’re only going to spawn more enemies if the PlayerHealth is more than 0. Then we need a reference to the game object of the enemy that we want to spawn. So those prefabs are effectively game objects that are stored as an asset. So we have a reference to the particular one we want to spawn. Then we have a spawn time, which is 3 seconds and obviously because it’s public we’ll be tweaking this, changing it to balance the game. And then we have a public transform array, so you’ll note these 2 open closed square brackets called spawnPoints. We’re not going to use that in this example. We’re going to use one spawn point per instance of this manager. But if you wanted to you could have a whole bunch of spawn points, and you can take this project away and create more spawn points and try it out and have fun with it. So we just wanted to give you that option. So when the game starts we use a function called InvokeRepeating and what that does is it basically means you don’t need to have a timer effectively for something that’s going to repeat.>From the very start of the game we call the spawn function, so we name it as a string, and we have an amount of time to wait before doing it and we have an amount of time to wait before repeating it. We’ve just reused spawnTime, we could set that to 0 but we’ve just reused it so there’s a bit of a breathing space at the start of the game. So InvokeRepeating will just repeat this every, well, 3 seconds. And we’re checking if the player has some health and if he doesn’t we return but if he does, if he’s still alive and kicking then we are going to instantiate our enemy in to the game. So we have this integer called spawnPointIndex. Now when you create an array, a list of things, an integer is there to represent the point in the array. So as Mike mentioned earlier, any list of things, any time a computer counts it starts at 0. So this is the index, the index is the number in the list as an integer. So we want to pick a particular spawn point and spawn from that point. This way if you do choose to use an array, a number of different spawn points then it will pick a random one to spawn at, making the game a bit more lively. So the way we pick a random one, is we say Random.Range. We start at 0 and we pick any number up to the length, so the final number of spawn points. It will pick any of those spawn points. It can help to think of an array as an accordion folder, if you know what that is, a folder with a bunch of slots in it. It’s still really one folder, that’s what an array is, it’s just one variable, but if you open it you’ve got a whole bunch of slots inside. And that’s effectively how an array behaves, you can look at the first slot, the second, the third, the fourth and you can put stuff in there. So an array of these spawn points is just a single object, a single array of those spawn points, if you open it up you will see all of the various ones inside of it. And that’s what we’re doing, we’re just picking a random one pulling that out and saying ‘that’s our spawn point’. And we’re reusing that information so we’re saving that as a number so we’re picking a number and saving in to that variable. And the reason we do that is because of this instantiate line. Instantiate just means create an instance of something, so spawns effectively is another word for it. And it has 3 properties, the thing to spawn, where to spawn it and what rotation it should have when it’s created. So the first one is obviously the enemy, the one that we assigned to our public variable and we’ll do that shortly. And then the second one is using that spawnPoints array and then we’re parsing in to the square brackets which point in the array. So if I was to parse in 0 it would choose the first transform that we drag and drop in to our list. But we’re going to allow it to use the random one that it’s just picked so every time Spawn runs it will pick a random number within that list of different spawn points, parse it in to the position and rotation. So remember that this is a transform and every transform has a position and a rotation. But that is very simply our EnemyManager. I’m going to switch back to Unity now. So we have this EnemyManager game object now and we have this EnemyManager script on it and as was hinted at this EnemyManager script was built to be modular, which means we can put stuff on, we can take stuff off we can have a bunch of spawn points, kind of future proofing this game so you guys can keep adding to it and stuff like that. Before we start putting in the enemies and get them spawning we have to generate these spawn points where the enemies are going to appear at. So the first thing we’re going to do is setup a spawn point for our Zombunny. And also if you can still see the animator window here we’re just going to click back over to scene view because we don’t really need the animator view anymore. What I’m going to do is create an empty by clicking the Create drop down in the hierarchy view and this empty game object is going to be my Zombunny spawn point. As such I’m going to name it ZombunnySpawnPoint and we can see it where it kind of exists right now but that’s not where we want it to go. And so what we want to do is place this where we want the Zombunnies to come from. Now as was hinted previously we could have a bunch of different spawn points but we’ll only have one per enemy for now. As we move around in our scene we can see the spawn points where it is right now with these arrows to denote where it is in the scene, but we can also give a customised icon to this object so it becomes much easier to see it in the scene view and it’s really easy to do so I’m going to ensure that ZombunnySpawnPoint is selected in my hierarchy and then I’m going to look at the top of the inspector and see this little colored cube right here at the top of the inspector, and if I click that I get a drop down that gives me all these sorts of options and using this I can pick an icon. Now the Zombunny is blue, I’ll pick blue so they’re color coordinated. Now that I’ve selected that if I look back in my scene view I’m going to see that ZombunnySpawnPoint has a name with this icon around it. So it’s very easy now to see exactly where that is, it stands out. I’m going to now position it. I’m going to supply the coordinates and rotation to position these, this is one of those things where it’s a really good idea to supply the exact values that we provide only because these spawn points are kind of behind bits of geometry inside a mouse hole, stuff like that, so if you’re off a little bit your enemies are going to start spawning in walls and they’re not going to because to come out and it’ll be a problem, especially in the mouse hole, which has a very narrow opening so it’s very important to get these numbers exactly as we have them. So for the ZombunnySpawnPoint we’re going to do the position of X to be -20.5. We’re going to have Y be 0, and the Z value is going to be 12.5. We are then going to provide a rotation which is 0 in the X axis 130 in the Y axis and 0 in the Z axis. Now we have the ZombunnySpawnPoint and it’s where we want it and if I look in the scene view there it is, I can see it, it’s much easier to see now because it has that blue icon. So let’s create our ZombearSpawnPoint. Now again I can right click Create New and stuff like that but in this instance what I’m going to do is duplicate the one I’ve already made. And so I can click on the ZombunnySpawnPoint in the scene and I can right click and select Duplicate or I can simply click on it in the hierarchy and hit Command-D on a Mac or Control-D on a PC. And that’s going to create an exact duplicate. Same name, same icon, same position, same everything. Now we have this as a duplicate, so let’s go ahead and change it slightly. I’m going to rename it from ZombunnySpawnPoint to ZombearSpawnPoint. And I’m going to change it’s gizmo, again using the drop down in the inspector I’m going to change it from a blue oval to a sort of fuchsia oval since the Zombear is kind of pink. And then I’m going to change it’s position and it’s rotation. Again it’s fairly important to have these accurate. Mine is going to be 22.5 in the X axis, 0 in the Y axis and 15 in the Z axis. The rotation of this is going to be 0 in the X axis, 240 in the Y axis and 0 in the Z axis. Now we’ve created 2 let’s go ahead and create the last one, we’re going to do the Hellephant. And the steps are going to be very similar. So with Zombear selected again I’m just going to press Control-D or Command-D or right click and select Duplicate, just make a duplicate of that object. And we are going to rename it from ZombearSpawnPoint to be HellephantSpawnPoint. Once created, again in the inspector I’m going to click the gizmo and this time I’m going to choose a yellow gizmo because the Hellephant has that yellow stripe to it. And then I’m going to set it’s position to be 0 in the X axis, 0 in the Y axis, 32 in the Z axis. I will then set it’s rotation to be 0 in the X axis, 230 in the Y axis and 0 in the Z axis. And so if we now look at our scene view in a zoomed out way we can see all three of our spawn points. We can see exactly where our enemies are going to be coming from once we have the EnemyManager able to start spawning those. So we’re just going to setup the first three instances of the EnemyManager to spawn our Zombunny. So if you click back on your EnemyManager you will see your EnemyManager script and that’s setup there ready to go but we already have things to fill in. The first thing we need to fill in is PlayerHealth, again we don’t want our EnemyManager to spawn enemies when the player is dead and so what we’re going to do is locate the player and we’re going to click and drag on to the PlayerHealth property of the EnemyManager and that’s going to locate the PlayerHealth script so that it only spawns at the appropriate times. Then we have this next section for enemy. This is the enemy that’s going to spawn, but if I look in my scene I don’t have any enemies, there are none, do we need to specify what enemy we’re going to spawn, we don’t have any objects here. Luckily as Will has already mentioned, because he’s classy like that, is prefabs are in fact game objects so if we look down in the Prefabs folder we will notice our enemies, we’ll notice our Zombunny and our Zombear and our Hellephant are there and they are prefabs. They don’t exist in the scene but they are still game objects and as such we can click and drag them in to the enemy property on our EnemyManager script and now it knows that it’s going to instantiate or create copies of that Zombunny prefab. Now we can see SpawnTime is 3, what that means is when our game starts it’s going to wait 3 seconds and then spawn a Zombunny. And then it’s going to wait 3 more seconds and spawn a Zombunny and so on and so forth. Over and over and over again. But it still doesn’t know where to spawn those. We have the script, we have the player, we have the enemy, we have the time, but if we actually expand this spawnPoints we will see size 0. Remember, this is an array, it’s a collection, we haven’t given it anything yet. It’s size is 0, there’s nothing in here. Now there’s a lot of manual ways I can add to this but there’s actually a really simple way. What I’m going to do is ensure that SpawnPoints is actually collapsed, and then I’m simply going to locate ZombunnySpawnPoint and click and drag it on to the name Spawn Points. Not down here anywhere, You will see on my mouse if you look at my screen when I click and drag and I move over the SpawnPoints I get this great + icon If I let go now it’s added to this collection. If I had a bunch of spawn points I can click and drag each on their the name and it will automatically add them to ‘the collection’, so at this point if I run this he will start spawning Zombunnies. So with that done we are going to save our scene and press play. So we’ve put one in of the EnemyManager. We designed this script to be modular so that you could reuse. We could have written a script that has arrays of different enemies and arrays for different spawn points, we just made this nice and simple. What that means is you can drag on more than one copy of this script on to your EnemyManager and assign the other game objects. So what I’m going to do is go back to the Scripts Manager folder and drag on a another copy of enemy manager. So I can just drag in to that empty space and let go. Then as before I need to assign my Player to PlayerHealth, and I need to assign an enemy So this time I’m going to choose from Prefabs Zombear. And I’m going to drag my Zombear spawn point and drop it on to the Spawn Points array, which will populate it. Finally, one more time, Scripts Managers Enemy Manager. Drop it on again. Third and final time. And we’re going to assign the Player to get the PlayerHealth script. We’re going to go in to our Prefabs folder. Drag and drop the Hellephant game object. This time we’ll set a different spawn time to 10. And we’re going to drag our Hellephant spawn point on to the Spawn Points array so I’m going to leave that open like that So we’ve effectively given it 3 copies of the same script We’ve assigned different enemies to spawn and different spawn points to spawn them from. And we can choose different spawn times, so if we want a spawn time of 10 for the Hellephant we get fewer of them, so it’s kind of like a tank kind of class, if you’ve played Left For Dead. So go ahead and save, and play. And you should be able to play a 3 enemy-based game. Remember that we put different spawn points at different places. The Zombunny is coming from behind the dolls house. The Zombear is coming out of the mouse hole. And the Hellephant’s are coming from behind the chest of draws in the upper corner of the game. And your score should be working and if they manage to corner you you should be loosing health. We really should have made you lose health if you stepped on the Legos because that hurts so much. Yup. So that was the end of phase 9 and we have 1 more phase to go. Subtitles by the community

88 thoughts on “Survival Shooter Tutorial – 9 of 10 : Spawning Enemies – Unity Official Tutorials (new)

  1. I got a problem here. I completed the project with these tutorials. I set the spawn time is 3 seconds to 3 enemy, I have score on the screen, the game over clip. When I decide to build and run the game, I choose the platform is Windows x86. As a result, I got the game running but it's very different from the project, it doesn't have the Score Text on the screen and the Game Over Clip. What happened?

  2. Could i have some help please i have been following i can kill and spawn the bunny's but they don't i have made my own map for it can i have some help for fixing it please

  3. Hi folks using unity 5 and theres an issue when my enemies spawn in it freezes and sais object reference not set to an instance of an object it will let me put the health in place of player health but then the spawned enemy sais it cannot get a reference?? anyone help

  4. When i kill my hellephants they just stand there and play the moving animation whats wrong?

  5. at 10:20 why the script is

    if(playerHealth.currentHealth <= 0f)
    int spawnPointIndex = Random.Range (0, spawnPoints.Length);
    Instantiate (enemy, spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation);


    if(playerHealth.currentHealth > 0f)
    int spawnPointIndex = Random.Range (0, spawnPoints.Length);
    Instantiate (enemy, spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation);

  6. Need Help!! (Already Googled)
    After creating prefabs and using them, image gets pixeleted and blurred. I changed import settings, but after some time settings get set to default.

  7. I dont know why they use Random.Range if the range is betweeen 0 and 1.
    Each script have only one spawnPoint so the Random.Range function of each script always gonna get 1 because it has only one spawnPoint attached.

    So I decided modify the script, I understand than the hellephant enemy allways will appear at 10 seconds and the two another enemies each 3 seconds… maybe this last enemies will appear randomly so, I hope help you withit:

    // An array with the three enemies ordered: Zombunny, Zombear and Hellephant.
    // The position where the enemies gonna appear with the same previous order (1. Zombunny, 2. Zombear and 3. Hellephant)

        public GameObject[] enemies;   
        public Transform[] spawnPoints;

        // Each 'spawnTime' seconds this script will clone a Zombunny and Zombear enemy.
        // Each 'spawnTimeForHellephant'seconds it will clone a Hellephant enemy.

        void Start ()
            InvokeRepeating ("Spawn", spawnTime, spawnTime);
            InvokeRepeating ("SpawnHellephant", spawnTimeForHellephant, spawnTimeForHellephant);

        void Spawn ()
            if(playerHealth.currentHealth <= 0f)

            // In the video they use Random Range for only one element… its not necessary.
            // BUT i can do something for them: 

            // We have 2 enemies in the array without the hellephant, It choises randomly one of them:
            int enemyToCloneIndex = Random.Range(0, enemies.Length – 1);
            // Now clone it
            CloneAnEnemy( enemies[enemyToCloneIndex], spawnPoints[enemyToCloneIndex] );

        // Spawn an hellephant enemy
        void SpawnHellephant()
            if(playerHealth.currentHealth <= 0f)

            // I put the hellephant enemy at the array tail so…
            int hellephantIndex = enemies.Length – 1;
            CloneAnEnemy( enemies[hellephantIndex], spawnPoints[hellephantIndex] );

        // Clone an enemy 
        void CloneAnEnemy( GameObject enemyToClone, Transform spawnPoint )
            Instantiate (enemyToClone, spawnPoint.position, spawnPoint.rotation);


  8. Thanks Unity for great tutorial…. to traveler who travel so far finding and wondering how to make the spawning limit for easy/brutal level but just find really complex coding on google….. just add

    // GGWP JUST ADD //

    public int spawnLimit = 10; // in declaration

    and ..

    spawnLimit – = 1 ; // in spawn function below Instantiate line… compile then run

  9. Hi guys this is the first tutorial I have done with unity and I want to include levels… I think I'd no how to how to display the level number but what would I have to change in the enemy spawn script to create levels.

  10. Everything works fine in Unity 5.2.2 but I think EnemyManager should be a singleton; putting several EnemyManagers seems to be a bit weird.

  11. I dont get it, Bunny en phant spawns, bear allso spawns but are standing idle @ the door , they doesnt attack or following me what so eva . pls help 🙂

  12. +Unity Thanks for the tutorial, I am new to unity and this (survival shooter) cleared lots of things , thanks for the amazing tutorial and waiting for another great tutorial 🙂 …..

  13. I made the Hellaphant AOC and then at the prefab I wanted to add this controller instead of the EnemyAC (as they did in the video) but then Unity crashed, why? *Hmm, second time no errors or crash.

  14. Everything seems to work well besides this error I get from EnemyManager.

    Instantiate (enemy, spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation);

  15. For those who gets "object reference not set to an instance of an object" , make sure you DO NOT have more than 1 spawnpoints in your enemy manager. Having multiple at spawnpoints with no proper value is the cause. Just delete the elements apart from element 0.

  16. Help, please! I keep getting this error: Object reference not set to an instance of an object. Everything seems to work fine the first 3 seconds. Then, when my Zombunny appears my whole game freezes. I can't even move my player anymore.

  17. Okay, so within my enemyManager, it doesn't seem to want to let me define where it should fine player health, i.e. the "player" object. Click and drag over the box, no change. Select from the drop down menu, also no change. It needs this player health script to spawn the enemies – I'm lost, any ideas?

  18. When they show the people talking instead of the screen capture, the jumpcuts are jarring, but the audio is sublime. Very interesting.

  19. Why didn't you create an array for enemies and choose from that later on? I suppose that'd be easier and more elegant. Moreover, you can coincide the enemies with their respective spawnpoints' indices so that they will be instantiated at the appropriate spawn points.

  20. I downloaded the latest version of the assets package, but the prefabs folder does not have all of the elements that this video depicts. While I could simply drag them from the "completed prefabs" folder, that misses the point of the video. This is just an FYI in case the person responsible for managing the content of the assets happens to read this message. TY.

  21. I didnt have Zombear and Hellephant prefabs, so created one example of Zombear using available model, and attached all integral scripts and elements, just like Zombunny prefab. And it works fine, untill I shout him down, then Zombear just stand still without any movement and I'm getting a lot of mistakes. Bullets are flying around him, even if I'm shooting right in his body, but he still make sounds of hurt. Collider with rigidbody works still fine, so the only thing i can do – is moving him by pushing. HELP PLS :c

  22. im having issue when i have to place player into the enemy manager ( player health) i can't do it , and 2nd thing is that unity shows error kind a "object reference not set to an object.." does anyone have same issues ?

  23. In my latest version of unity there is no zombear and hellephant so I tried making them keeping zombunny as reference. My only problem is adding 2 materials to it. I am able to add either eye material or the zombearmaterial as component but not both. They keep replacing each other when I drag and drop them as child under the zombear. Is there somebody who figured out how to do that?

  24. i was wondering why i didn hit the Hellephant and the Zombear after looking 5 mins to the prefabs i did see that in layers it was not set to shootable + hitparticles were not set now is it working

  25. For those whose 'EnemyManager' was not taking the 'Player' as a reference…

    Drag and drop the 'Player' from the 'Prefab' folder that is in the 'Completed_Assets' folder in the 'Project' folder to the game Hierarchy.
    DO NOT delete the ORIGINAL 'Player' game item in the Hierarchy. You still have to transfer the references in the original 'Player' item to the new 'Player (1)' item you just dragged in.
    The new 'Player' game item will have ZERO references so you will have to look what references the original 'Player' item has and redo them.

    The some references that need to be redone are…

    -The camera follow reference
    -The 'HeartSlider'
    -and 'DamageImage' still need to be re-reference.

    Once you re-referenced your new 'Player' game item into the Hierarchy, you can delete your old 'Player' item. If there are errors that still come up, you can look at the console and address those errors in the script they describe.

    Like if this helped.

    P.S. – If anything goes wrong, use 'Ctrl+Z' (for Windows)

  26. I copied your script like exact bro, except I removed playerhealth part coz pft, and I keep getting this error on your last with "Instantiate (enemy…"

    "Only assignment, call, increment, decrement, and new object expressions can be used as a statement"

  27. I'm having an issue where I make the HellephantAOC and then drag my EnemyAC into it like they did, except mine is not making a list so I can't drag the animations in. Anyone got any solutions?

  28. when i delete my zombunny from hierarchy it disappears in scene view anyone knows why and im receiving errors Asset with ?GUID

  29. Just wondering, earlier they mentioned if we are repeating code or a part of code then we are almost always doing something wrong. At the end of this phase they added the Enemy Manager script to Enemy Manger game object three times. It gave me a feeling like its not the right way or there must be a better and effecient way to do this. Anyone else thinks like that, if yes and if you've done something about it then let me know. Im new to Unity, just started.

    From the top of my head we can use spawnpoint array and emeny object array somehow because we are using three scripts to handle these two variables for all three enemies.

  30. Hello all,  I have the Hellephant and ZomBear chasing the player. However they do not take any damage?  Any one have any ideas to fix it?

  31. before dragging the enemy(zombunny,zombear ,hellephate ) into the enemy slot in the enemymanager make it's a prefab or you 'll get an error

  32. The Hellephant and the Zombear takes damages but they don't die, I've got this error : "NullReferenceException: Object reference not set to an instance of an object"

  33. Hi,
    I'm hoping you can give me a tip.  I found that the three spawn points in the game give the game little replay value, especially if u are using unity 5 and only the zombunny is available.  So I wanted to create random spawn points.  How should I do this?


  34. It seems that no matter where I place my spawn points, the enemies all spawn right in front of me and only in a straight line. I have the spawn points spread out far and wide, but they all spawn two inches in front of me. Any help there?

  35. Yeah so all of the file folders were setup nothing like they were in the vids, sometimes there was even multiples of the same items (prefabs and mine) so I constantly had to pause and find which asset to use then rewatch what I was doing in the first place. The other headache, the 'completed assets' whether it was code or a prefab when I did accidently add them they'd usually cause some kind of compiler errors I didn't know what to do with that I could never fix and actually ended up restarting the whole tutorial twice because of it. This was my third go, got this far with no errors until I got here. The problem I had here was with the Player Health script not registering no matter how I added it in the EnemyManager (from prefab asset player or my own) EVEN when it did register the PlayerHealth script in the EnemyManager it wouldn't spawn an enemy and i'd get an error saying there was a problem with this code: if(playerHealth.currentHealth <= 0f) saying the reference was null and was which I thought was weird since when starting my health is full and all of my other scripts/assets were working fine. I'm pretty sure it's because of the HUGE FILE mix up between prefabs and my 'player' built stuff EVEN though I did everything EXACTLY how it was in the vids. I've spent too much time just trying to rebuild this game lol but with the horrible file management going on in Unity had to call it quits. Other than those problems I did have fun-ish learning everything until having to quit/delete the project since I couldn't fix it and eventually couldn't even try to play because of compiler errors I didn't know how to fix. ^_^ The whole point for me was just to learn the basics of Unity/VS and how-ish to do things i'll likely want to later on, like adding components to objects etc and I definitely learned what I needed to and more so thanks for all the great info.

  36. Is there a way to spawn them in random areas? Maybe set certain locations as spawn points, but every-time they spawn, it can either be on one of the many spots? Is there a way to do that?

  37. Gave ZomBear EnemyAC in the animator component yet it does not animate if anyone can help that would be great. Thanks!!

  38. Nice tutorial, sometimes I wish you explain better certain matters but I understand that you have your time to talk and stuff. One last video.

  39. If you add the hellephant and zombear prefabs that are already completed you need to replace their script components with the ones you edited already, the enemy movement, enemy and enemy attack so it wont give you an error.

  40. PLEASE PIN For anyone that is stuck finding the ZomBear Prefab. From what i can see it wasn't included in the project, here's what you need to do:

    1. Put your Zombunny prefab back into the scene so you can inspect it.
    2. Go to models > Characters > ZomBear and add it to your scene.
    3. Copy each component from the Zombunny and paste it into the ZomBear.
    4. Add "EnemyAC" Controller to the ZomBear.
    5. Add "Shootable" layer to the ZomBear.
    6. Find your "HitParticles" prefab and make that a child to the ZomBear.

    Then create a prefab for the ZomBear you just created. That's all.

  41. Remember to add the other enemies onto the 'shootable' layer in the top of the inspector window if you are shooting right through them

  42. I finished the game but when I hit play. The hellephant and zombear would spawn but would get stuck on their spawn point. They have their animations but I also cant shoot them. My zombunny is completely fine. The scripts in the zombear and hellephant prefab are grayed out. I looked it up in a unity forum and they said that its a prefab problem. Help.

  43. for anyone having issues with the null reference bullshit; select prefab > zombear & delete the scripts attached to them as they are old. Reattach the ones from your own scripts folder (it should be for movement, attack, and health)…do the same for the hellephant.

  44. GO TO Assets->_Complete-Game->Prefabs, and drag the Zombear and Hellephant into your scene. Then go back to your Assets->Prefabs and drag them from your hierarchy to your Prefabs folder. Job done.

  45. I am always annoyed by the overall poor coding style standard in so many tutorials. Public variables start with a big letter, private ones start with underscore, parameters with small character, and a hundred other issues — get ReSharper and follow the hints and warnings.

  46. If you have a problem with the ZomBear or Hellephant not attacking the player but you copied the prefabs FROM _Complete-Game folder, then you need to remove the scripts attached to them and re-add YOUR scripts to them to update them all correctly.

    Also if for some reason your bunnys, bears or hellephants do NOT attack the player OR can be attacked by the player, but do follow you, all you need to do is:

    Drag and drop the enemy prefab you wish to change INTO THE HIERARCHY, then do the follow when you select them in the hierarchy;

    Player cannot hit enemy:
    add a capsule collider (to hit them) to whichever prefab enemy you cannot hit and fix the correct radius and hit for each enemy.

    Enemy cannot hit player:
    add a Sphere collider to whichever enemy cannot attack the player, make sure you CHECK "IS TRIGGER" and fix the correct radius for each enemy.

  47. Really i love Unity, but those half assed tutorials with outdated scripts or forgotten assets are really annoying….

  48. I got strange problem. Evrything is wokring exepect Hellephant's. They keep making move animation but doesnt move, doesnt do damage , doesnt attack. Any ideea why ?

  49. My zombunny is just stuck at the spawn point and won't move. I can't kill it either. What should I do

Leave a Reply

Your email address will not be published. Required fields are marked *