[GAME] My Glitch Garden with some miner changes, including extra Attackers!

I’m finally here! After stopping halfway through this section and re-watching the entire course so I have a better understanding on what’s being taught, I’ve finished the game!

There are four levels in total, and each one introduces a new Attacker. So as you can probably guess there are two extra Attackers, a Crab and a Flamingo. The Flamingo is entirely bone-base animated. As for the Defenders, instead of the Gnome I have a Cooking Vendor that shoots sandwiches.

I added lives, so instead of getting Game Over when one Attacker enters the Lose Collider you get five chances.

I coded the Slider timer differently to how Ben did it so doesn’t move as smoothly. And for fun I made the Slider handle a Lizard. :smiley:

Now, there are some problems with the music still. In the Options menu there’s no music playing, and I can’t get the music to loop in the levels. I did make a topic asking for help on that, which you can see here. Also the music seems to be off by default, even though that’s not how I set it in the code, so don’t forget to go to Options and turn it all the way up. :slight_smile:

Anyway, here (Old link removed) it is. Hope you like it!

Edit

Made some changes!

Firstly, influenced by @Brian_Robson’s horde levels, I made a fifth level where all of the attacker’s spawn frequencies are increased.

Secondly, I added a survival mode, which you can turn on in the Options, who’s only difference is that your lives don’t reset between levels, and it has different music.

Oh and the Crab is visible now. :slight_smile:

Now, I have been getting an error when I try to play it. (Edit: This has been solved). Here it is!

3 Likes

Nice mushroom NPC! Cool addition. I like the point system also. Level 3 seemed to be easier then 1 and 2, but maybe thats just coincidence. I couldnt beat the crab tho :wink:

1 Like

@Kookgek Thanks man. Yeah that would be a coincidence due to the random spawning system. The only change is the Crab being added.

On the Crab, I noticed yesterday he doesn’t appear until he attacks. Oops! Did you get that?

1 Like

Very nice James, I especially liked the in-between scene messages and also the little croc on the slider handle :slight_smile:

The addition of the lives mechanic was good and it was refreshing to see some alternative sprites in use.

I spotted that the in-between scene background doesn’t quite fill the screen (vertically) and also that the music seems off by default.

Very enjoyable game though and well done :slight_smile:

Thanks @Rob. That means a lot. :slight_smile:

1 Like

Hi James

I really liked the balance with the costs and the star-income, and loved the burger-thrower.

I did have some problems though. I don’t know if it just wasn’t loading properly for me, but the image in the menu background was coming out garbled for the bottom 2/3s - and also I didn’t have any crab sprites rendering while walking (they suddenly appeared only while attacking) - although the defenders seemed to recognise they were there and start shooting. I’m not sure if the sprite just didn’t load up in my player…

Good job though!

Thanks @Brian_Robson. I spent quite a while balancing the star costs so I’m glad someone else thinks it works. :slight_smile:

I’m not seeing a messy image myself so I can’t speak to that. But as for the crab, yeah it isn’t appearing for me until it attacks, either. I’ll have a look at that, but I’ve been having other ideas of what I’d like to put in to the game, so I’ll re-post it when I get those done and hopefully with the crab problem solved. :slight_smile:

1 Like

I would be more than willing to give an updated version another test also, feel free to tag me (@Rob) when you post an update James :slight_smile:

OK. So, to perfectly honest I’ve been neglecting this project while I’ve been doing the Complete Unity Developer 2.0 course, and it’s only because my main PC is having problems that I decided to get back to this. And I’ve encountered a problem would like some help. So if you could indulge me, here we go. :slight_smile:

I’ve made a Survival mode where your lives stay the same between levels. That’s done and working, but I decided to be a bit ambitious and wanted to make it so you can switch between normal and survival mode in the Options scene.

So first I created a Survival mode key in the PlayPrefsManager script, which you can see here (not the entire script):

Yeah I just kinda copied the Master Volume Key, but I think it looks good hehe.

So, then I made the appropriate changes to the Options Controller script:

OK, and now the LevelManager script. Here’s where I’m having problems. This is the script:

It’s the LoadSurvivalLevel method we need to focus on. I gave this to the Start button, because I want to make it so that the survivalSlider’s value determines which mode you go to when you hit Start. The problem is, whenever I hit Start, I’m getting an error on line 28, the good ol’ “NullReferenceException: Object reference not set to an instance of an object”.

So I’ve done some reading and found that it’s to do with it not being able to find the GameObject being asked for. As part of trying to solve it, this:

optionsController = GameObject.Find(“OptionsController”).GetComponent< OptionsController >();

Was originally this:

optionsController = GameObject.FindObjectOfType< OptionsController >().GetComponent< OptionsController >();

Now, the OptionsController was originally only an instance in the Options scene, so I’ve tried prefabbing it and putting it in the Start scene. When that didn’t work, I tried publicly exposing OptionsController in the LevelManager script, and dragging the OptionsController GameObject instance in to it. So it’s not even finding it in the script anymore, I’m sure it knows what it is! I comment line 28 since I don’t need to find it in the script anymore, and still get the same error, this time on line 30!

So yeah, this is getting pretty stressful. Please, someone, put me out of my misery! Thanks. :slight_smile:

Hi James,

From your description, it sounds like it just can’t see the GameObject because it isn’t in the scene, but equally, I don’t think you really need it to be either.

As you are storing the selection of the game mode from the Options scene, why not just access those PlayerPrefs again in your LevelManager and load the appropriate scene based on the returned value?

You could perhaps go a step further and have a separate method in your LevelManager which returns the name of the scene to load, based on the options stored in your playerprefs, which it just hands to the standard LoadLevel method - rather than having the two separate methods.

or…

In the same way you are using the MusicManager, you could perhaps create a new GameObject/script “GameMode” and then set the values of the GameMode from your OptionsController. A GameMode object could then be in each scene to reference the mode and the difficulty as set by the options.

Oh man, I’ve been so silly! So, I actually did try to get the values from the PlayPrefsManager before asking for help here, but I couldn’t get it to work. In the if statements, I was trying to use SetSurvivalMode() and getting the value from the brackets and, yeah, wasn’t working. Since you suggested it, though, I decided to try again, and this time used GetSurvivalMode to get the values, and it’s working. :stuck_out_tongue:

1 Like

Glad to hear you’ve got it working James, well done :slight_smile:

Thanks @rob!

Changes have been made! Edited the top post with a link! :slight_smile:

1 Like

Guess I better go and have a play then! :slight_smile:


Updated Thu Dec 07 2017 23:04

Really nice, just managed to play all levels and won! I’m not sure whether my eyes deceived me, or whether it was a thing, but I noticed a crab walking across the bottom row on one level and it disappeared… shortly afterwards one of my defenders also disappeared. Just thought I’d let you know.

Really nice though, feels well balanced and good fun :slight_smile:

Thanks Rob!

I’ll see if I can track down that crab. :slight_smile: Do you remember what level it was?

1 Like

Hi James,

Just had another player, I believe it is level 5, it’s the first level where the cactus is available as a defender.

The crab seems to randomly appear on a row, attack, then disappear, then re-appear. This time round I had one appear on both the top and bottom row.

No significant issue with the crab, what is challenging is that you may have a row without any defenders, just a star generator for example, the crab then appears, attacks and destroys the star generator, and then moves across and wins the game - but because the crab is invisible - you do not have an opportunity to place another defender, or know when it’s about to cross the line as it were.

Here’s the cheeky fellow :slight_smile:

image

I quite like the idea of the crab burrowing, but if this is the intended feature, perhaps the crab needs to make his presence a little more obvious before an attack. For example, maybe a little wobbly raised ground sprite could move across a row, then, the crab raises up out of the ground, pauses briefly, carries on moving. The reverse could be applied to make him burrow again. An example of something very similar would be the miner troop type in Clash of Clans, the first 3 seconds of this video demonstrate what I’m trying to convey.

Incidentally, I also noticed on level 5, although I wonder if it is applicable to all levels, that a croc attacked a star generator and then continue to move on (off the screen, game over etc), but the star generator was still there. I’ve seen this in a few student versions of this game and I wonder whether perhaps, there is the possibility to actually place more than one star generator under certain circumstances (I had clicked else where on the screen at this point), it would perhaps make sense, e.g. first croc attacks star generator, but is effectively attacking the star generator “on top” - destroys it, attacking flag is reset, but then because it’s own box collider is effectively inside the star generator which is underneath the first, no collision is detected and the crocs continues to walk off the screen.

It occurs randomly, but you could test this behaviour by deliberately placing two star generators, one on top of the other in a scene and then have a croc attack.

No no, the crab is meant to be visible. That’s worrying, I thought I had solved that. When I run it in the Unity editor he is visible when he walks, so it might just be a problem with it being on the web. Unfortunately I can’t check it myself because of that error I keep getting. It’s good to hear you’re not getting that! The only thing I can think of are you sure you’re clicking the right link? The second one after the edit.

Oh, nope, I’d been clicking the one above the Edit

I will try the bottom link then! :slight_smile:


Updated Sun Dec 10 2017 13:48

Yep, I get that error too…

Ah, hehehe. I tried doing a new build and re-uploading it to Gamebucket, but still getting an error. Do you have any suggestions?

Hi James,

Try the following;

  • tick Development Build under Build Settings

    image

    With this option selected, the JavaScript isn’t minified and as such, the stack trace that is produced should be a little bit more readable.

  • Rebuild and publish, please provide an updated link above

  • Browse to your game using Google Chrome

When the error occurs;

  • right-click on the page (not the frame with the game in it)

  • select Inspect
    image

  • click on the Console tab within the Developer Pane

You should be able to scroll through the stack trace and hopefully this will shed some light on to the issue. If you aren’t too sure, just ping me back on here when you’ve updated the link for the development build and I will have a look too.

Privacy & Terms