Create A 2D Idle Clicker Game in Unity! Tutorial 4 | Spawning Animals -

Create A 2D Idle Clicker Game in Unity! Tutorial 4 | Spawning Animals

Views: 239
Like: 15
Hey guys, what’s up! Tim Here!
Here is how we get animals spawning in once they have been rounded up! The health bar signifies how long until the animal is caught and then a new random animal replaces it! I hope you all enjoy it!

Find the Code on Github:

Please Like and Subscribe for more! 👍
Check out My Latest Video Here!


Visual Studio Code:

▼ Follow Me
Instagram: TimmyJTech

▼ Help me out by joining my Patreon!

▼ Join my Discord Server!

🎧 Music 🎧
▼ Background Songs ▼
▼Title: [BLOSSOM.] (w sugi.wa)
▼Title: Evening Tide
Artist Name: Kupla
▼Title: [REVIVE.]
▼Title: within
Artist Name: leavv
▼Title: Moonlight
Artist Name: The Deli

▼ Outro Song ▼
Title: Infinite
Artist Name: Valence

#idleclickergame #unitytutorial #TimmyJTech


  1. 7:14 you secretly change from EnemyManager to AnimalManager….

  2. For anyone watching this, at 12:36 make sure you create the prefab in your assets and not in your Hierarchy and then drag and drop your different elements.

  3. hey man, im getting this error : 'GameObject' does not contain a definition for 'Length' and no accessible extension method 'Length' accepting a first argument of type 'GameObject' could be found (are you missing a using directive or an assembly reference?)…. i've checked everything and is all correct, don't know what is wrong

  4. Hi Timmy, thanks for the tutorial. I have a problem, the new monster spawn outside of the canvas for some reason, I already double checked the code and it seems to be correct. Do you know why this happens ?

    edit: nvm I found out why, I didn't add the reference to the canvas on the monster manager

  5. I get errors but none of the ones you get. On the line you put public Animal curAnimal it just keeps saying Animal cannot be found

  6. Not sure if you're still responding to comments but after writing all of the EntityManager.cs file (I'm using Entity instead of Animal) I get a CS1061 error because the GameObject[] doesn't contain a definition for 'length'. This is weird because I made sure I wrote it exactly how you did but you didn't get this error, also I wrote it as an array so I don't know why it's having an issue with entityPrefabs.lengthI'll copy paste all my code below and here is the error exactly as written in Unity: 'GameObject[]' does not contain a definition for 'length' and no accessible extension method 'length' accepting a first argument of type 'GameObject[]' could be found (are you missing a using directive or an assembly reference?)CODE:using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class EntityManager : MonoBehaviour {

    public GameObject[] entityPrefabs;

    public Entity curEntity;

    public Transform canvas;

    public static EntityManager instance;

    void Awake() {
    instance = this;

    public void SpawnEntity() {
    GameObject entityToSpawn = entityPrefabs[Random.Range(0, entityPrefabs.length)];
    GameObject obj = Instantiate(entityToSpawn, canvas);

    curEntity = obj.GetComponent<Entity>();

    public void ReplaceEntity(GameObject entity) {

  7. thank you for this tutorial , it helps me a lot!

  8. Hello, the animals seem to be appearing in random order. How can make it to cycle the list in an order?

  9. Somehow the Text doest work at all. The only Text i can drop into the GameManager Script is the GameObject – 3D Object – Text – Text Mesh Pro. That Text gets stuck behind the Background image. No idea how to fix any of this.

  10. I noticed when we created the 3 scripts before that we named one EnemyManager and then changed it to AnimalManager inside unityThis doesn’t actually change the name inside the script and therefore gave me errors while working on the AnimalManager script. I simply copied my code and recreated the AnimalManager script (with the correct name from the start)in unity then pasted my code in there and everything works fine now. If anyone else is having this problem with the AnimalManager Script just check the Public class name (next to MonoBehaviour) and if it still says EnemyManager then do what I did.

  11. My Prefabs are all on the screen at once not just one random one?

  12. My text isnt working or updating, @ 4:45 you did a jump cut and then it showed a '0' after the dollar sign. Im wondering what did you do to display this?

  13. Once again a great tutorial cannot wait to see more!

  14. Did you duplicate the Duck Prefab, then change the name and png? @12:32
    Also, my duck does not respawn when I 'caught' it.
    Also, Unity 2019 is pretty close, I just had to change the AnimalManager.AnimalPrefabs.size to 1 in the Inspector…
    Do I have to do this all over in Unity 2021, due to some compatibility error?

    I was able to follow you up until the duck not respawning, and not knowing if you duped the prefabs quickly, or if you crafted each one all over again from scratch.

  15. Ahah! I found an issue in my Unity interface, the "Animal Manager (Script)" has 3 Animal Prefabs. The first one, Element 0, gets deleted upon capturing the animal, then is displayed in the Unity interface as "missing". The animals rotate between the remaining 2 of 3 animals correctly. But I need to fix this bug first. Is there a reason it is deleting the Element 0 prefab and not allowing re-selection of it? It was added to the canvas, iirc.

    I was able to stop it from being "displayed" as missing, by adding it directly from the Prefabs folder to the Animal Manager (Script) of the Unity interface, but it is still acting the same way and Element 0 is never selected from the array for spawn again. hm

    For the time being, I am going to use a potentially bad technique, but simply adding two of the first animal to the array of animals, so that the animal can be spawned.

Leave a Reply

Your email address will not be published.