Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by sparky14 · Nov 26, 2013 at 05:46 AM · spawnspawningclonezombiewaves

How to make the clones of a zombie continue to clone?

Basically I have a scrip to spawn zombies. I would like them to spawn in waves, but that is another story. My issue lies with the main zombie prfab. Whenever I run the game and I kill that first zombie. It no longer will make zombies. How do I fix it?

pragma strict

-----variables start--------

var zombie : Transform;
var clone : Transform;
var zombiesSpawned : int;
var zombies = 11;
var player : GameObject;
var spawn : boolean;
var min : int;
var max : int;
var wait : int;
var spawnPoints : Transform;
var positions : Transform;
------variables end --------

// on start I set min and max, set spawn to true, and set a random number value
function Start ()
{
min = 1;
max = 10;
spawn = true;
wait = Random.Range(min, max);
}

// Update I have an if statement that calls the function Spawn
function Update ()
{
if(spawn)
{
Spawn();
}
}

// The function Spawn is where I believe my issue lies.
//This is where I make more zombies.
function Spawn()
{
if(zombie)
{
Instantiate(zombie, transform.position, transform.rotation);
zombies++;
NewWaitTime();
spawn = false;
SetSpawn();
}
else
{
Instantiate(zombie, transform.position, transform.rotation);
zombies++;
NewWaitTime();
spawn = false;
SetSpawn();
}

}

// a little extra if you can help why isn't it spawning more than one zombie?
function SetSpawn()
{
if(zombiesSpawned == 0)
{
zombiesSpawned = (zombies + 12);
}
yield WaitForSeconds(wait);
spawn = true;
}

function NewWaitTime()
{
wait = Random.Range(min, max);
}

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image rct3fan24 · Nov 26, 2013 at 07:16 AM 0
Share

You should use the code thingy. I don't know what to call it. Just click the button that says "101010", and paste your code into that. Don't paste it straight into the text box, because that's ugly. Here's an example:

Without code formatting:

function Update() { //Hi, exampleness. if(true) } //Do a thing } }

With code formatting:

 function Update()
 {
     //Hi, exampleness.
     if(true)
     {
         //Do a thing
     }
 }
avatar image sparky14 · Nov 26, 2013 at 09:33 AM 0
Share

I honestly didn't know how to do that. SO I tried to make it as neat as I could.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by EnglishMuffin123 · Nov 26, 2013 at 06:18 AM

Well looking at your code it seems that your problem lies where you expected it. Your if statement says if(zombie) but zombie is a transform, not a boolean. That's probably throwing some errors for you. I'm not sure if the code will go on to the else case, but try fixing that and seeing what happens.

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sparky14 · Nov 26, 2013 at 06:23 AM 0
Share

Well I get no errors. I get run time errors with it. Whenever I kill the prefab zombie it is copying it freaks out and says pretty much it can't find zombie. This may be due to the probelem its death script deletes the game object zombie?

avatar image EnglishMuffin123 · Nov 26, 2013 at 07:02 AM 0
Share

If you wait before killing the zombie does it spawn another zombie? Also, your variable zombiesSpawned is an unassigned int. You're never going to make the if statement true since you're never giving it a value. You're only spawning one zombie because your instantiate only spawns one zombie. Your variable zombies acts as a counter but does nothing to add to the zombies being spawned. To do that try a for loop (if that's what you're trying to accomplish)

avatar image sparky14 · Nov 26, 2013 at 07:21 AM 0
Share

I didn't notice that about zombiesSpawned thank you. And if I don't kill the first zombie. They will spawn and continue to spawn. I did make sure to test that.

avatar image EnglishMuffin123 · Nov 26, 2013 at 07:29 AM 0
Share

Ok, what have you placed this code on? An empty object or the zombie itself? Also, what's the var Clone for?

avatar image sparky14 · Nov 26, 2013 at 07:32 AM 0
Share

I was trying to make it copy the clone aka the var clone. And it is place on the zombie prefab itself.

Show more comments
avatar image
0

Answer by rct3fan24 · Nov 26, 2013 at 07:12 AM

If you could somehow place the prefab zombie somewhere the player can't get to it, or vice versa, that would work. The prefab zombie would sit in it's place, while the scripts clone it into the play area. Not sure if this would work with your situation, but give it a shot...

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sparky14 · Nov 26, 2013 at 07:20 AM 0
Share

I would do that but I am going to make it waves. When all the zombies die then the wave will end.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Mob spawn and start comming to me 1 Answer

spawning game objects 1 Answer

Spawn waves & wait till it's killed, spawn again. 1 Answer

How to increase int every 5 waves? 1 Answer

How would I create a script that spawns objects more frequently as time goes on? 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges