Skip to main content

057. Unity3d Tutorial - Spawn Points And Spawning Mobs 3/3

See video

We continue with another tutorial in our Hack And Slash demo made with the Unity3d Game Engine.

In this video, we will finish off creating our spawning script.

Tags:

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Offline
Joined: Jun 3 2011

Hi
Again I'm not sure why this is happening but there is a little fix :
using your script, unity crashes every time it wants to return gos.ToArray() !

instead I changed the return type to List in the method defenition of AvailableSpawnPoints, and in Spawn method :

List gos=AvailableSpawnPoints();
and in the next for loop , instead of Legnth use Count, this way it works fine, same principle but better logic I think, after all when you are using List<> why don't return it and use it everywhere without need to converting it?

Offline
Joined: Jun 3 2011

heh why the List*<*GameObject*>* (without stars) in last post converted to nothing automatically? seems your comment script sees <> as html tag and it didn't recognize it and deleted it

Petey's picture
Offline
Joined: Feb 3 2010

Correct. The HTML being used on this site currently use those symbols as tags.

Offline
Joined: Jun 22 2011

I followed the whole tutorial but i used my own characters. When i hit play the spawn at 180 degrees like they are laying down. How do i change it to the upright position? When i made them as prefabs they
where standing straight.

P.S. also i used the old enemy ai script and noticed the same characters rotated to 180 degrees.

Petey's picture
Offline
Joined: Feb 3 2010

Check the orientation of your Mob when it is spawned. Is it right? Check the orientation of your spawn point. Is it right? Lastly, look at the placement. If it is to high, the mob may rotate to look at it. You can fix the last part in code.

Joined: Nov 6 2011

I am getting "ArgumentOutOfRangeException: Argument is out of range.
Parameter name: index" everything I press tab and try to get a target. Ive noticed in game master I dont get any targets targetted or found. Ive tried to go back to the first targetting video but thats not the problem everything works up to about spawn point 2/3 then it doesnt work. When I click on it it high lights

private void TargetEnemy() {
if(selectedTarget == null)
{
SortTargetsByDistance();
selectedTarget = targets[0];

it high lights the last line in here. Ive tried everything and retyped it like 4 times. it has not changed anything.

Offline
Joined: Oct 25 2011

Hello there Petey!

I found an error, don't know if you fix it in a later video, but here it is.

If you remove one of the mobs and respawns it, targetting works fine.
But if you have targetted a mob, then remove/respawns it, and after that try to target again, you get this error message:

MissingReferenceException: The object of type 'Transform' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.

Offline
Joined: May 6 2011

Hi, first off all i just wanted to say THANK YOU for these awesome tutorials, you have really helped me with alot of things! You are the best!

This tutorial was good, everything seems to work as it should, but i have one little problem. When i start the game, it spawns 3 random mobs, but i can't select them (target them). It works just fine if i put acouple of a mob prefabs on the stage and select them.
But with the mobgenerator it doesnt.

Unity gives an error, a null reference error, "target out of range". :

ArgumentOutOfRangeException: Argument is out of range.
Parameter name: index
System.Collections.Generic.List`1[UnityEngine.Transform].get_Item (Int32 index)
Targetting.TargetEnemy () (at Assets/Scripts/Targetting.cs:70)
Targetting.Update () (at Assets/Scripts/Targetting.cs:152)

I guess its because it does not update? I've checked so that the prefabs really have their "enemy" tags and so on.

Would really appreciate help, i understand if you got alot of questions from many people, just take your time. You are awesome!

Best regards

Jimmy

EDIT: Im so stupid!!! Just watched you later videos and found that you fixed it, i will let this post live on so other with the same error can take a look at the

http://www.youtube.com/watch?v=z2G5_y3MdnM&feature=player_embedded#!

and get it fixed!

:)