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 skully42 · Jan 19, 2012 at 12:02 AM · spawningzombie

Help with zombies Spawning

hey i am making a zombie game and i have to make them spawn i have a script but when the zombies spawn they dont kill me i need help here is the script:

var zombiePrefab : GameObject;

InvokeRepeating("SpawnZombie", 4, 4);

function SpawnZombie() {

 Instantiate(zombiePrefab, transform.position, transform.rotation);

}

Comment
Add comment
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

5 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Dan · Jan 19, 2012 at 12:04 AM

You probably have some logic that's not recognizing the new zombies. If you're looking for them by name, an instance usually adds "(Clone)" to the end of the prefab's name. Could be that.

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 skully42 · Jan 19, 2012 at 01:13 AM 0
Share

i looked and when they do spawn it says clone right after

avatar image
0

Answer by joeybbb · Jan 19, 2012 at 02:31 AM

here is a much better spawning script that i personaly made :)

 var AISpawn : Transform[];
 var allEnemies : GameObject[];
 static var currentEnemies : int = 0;
 var maxEnemies : int = 1;
 var minEnemies : int = 0;
 var spawn = false;  
 var spawnTime : float;    
 static var enemiesDead : int;   
 var enemies : int;   
 var round : int = 0;   
 var roundText : GUIText;   
 
 function Start()
     {
         while (true)
         {
            if(currentEnemies <= 1)
           {
               currentEnemies = 0;
               spawnTime -= 0.1f;
               ZombieAI2.speed += 0.3;
               round += 1;
               maxEnemies += 2;
           }
             if (currentEnemies <= minEnemies) 
                 spawn = true; // if minEnemies reached start spawning
             if (currentEnemies >= maxEnemies) 
                 spawn = false; // if maxEnemies reached stop spawning
             if (spawn){ // if spawning enabled create new enemy
                 // Randomize the different enemies to instantiate.
                 var obj : GameObject = allEnemies[Random.Range(0, allEnemies.length)];
                 // Randomize the spawnPoints to instantiate enemy at next. 
                 var pos: Transform = AISpawn[Random.Range(0, AISpawn.length)];  
                 Instantiate(obj, pos.position, pos.rotation); 
                 currentEnemies +=1;
             }
             yield WaitForSeconds(spawnTime); // free Unity for 2 seconds each loop anyway
         }
     }
 function Update()
 {
     roundText.text = round + "";
     enemies  =  currentEnemies;
     if(spawnTime <= 0.9)
        {
          spawnTime = 0.9;
        }
     if(maxEnemies >= 50)
        {
          maxEnemies = 50;
        }
     if(round == 50)
         {
             GO_PlayerDamageReciever.hitPoints = 100;
         }
 }
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 skully42 · Jan 19, 2012 at 08:52 PM 0
Share

hey i just tested this a few questions one where do i put the script and place where the prefabs and all that are supposed to go didnt show up and i got a few errors

avatar image
0

Answer by doomprodigy · Jan 19, 2012 at 02:28 AM

It is not to do with your enemy spawner. It has something to do with the prefab that you are instantiating. Look down the prefab in the inspector and see if the prefab has gaps such as None(GameObject) or it is missing scripts on the prefab. That was the case when I had a similar situation.

Comment
Add comment · Show 4 · 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 skully42 · Jan 19, 2012 at 08:36 PM 0
Share

alright i have two zombies in the begining game and they can kill me and i made a prefab to them and attached the prefab to the cube that spawns the zombies

avatar image doomprodigy · Jan 19, 2012 at 11:36 PM 0
Share

In the zombie prefab. Look at it in the inspector.. Is it missing anything such as None(GameObject) or missing scripts? In comparison to the one in the hierarchy.

avatar image skully42 · Jan 20, 2012 at 01:19 AM 0
Share

i dont think so i even made another prefab to be sure

avatar image doomprodigy · Jan 20, 2012 at 01:33 AM 0
Share

Your spawner is not the problem then. It is something in your AI Code.

avatar image
0

Answer by NhommeBeurreOne · Jan 20, 2012 at 01:43 AM

Hey!

Here a video tutorial that I found : Enemy Spawner. It work really well I tested it out.

Hope I'll help you,
Nbo

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 doomprodigy · Jan 21, 2012 at 11:18 AM 0
Share

Omg, Can you all not see it has nothing to do with his spawner. Idiots I tell you...

avatar image FLASHDENMARK · Jan 21, 2012 at 12:36 PM 0
Share

@Aaron_Lewis you sure got a mouth on you, don't you? There is no reason to call people idiots. Even if people got low-level of understanding about the subjects at hand there is no reason to be harsh.

avatar image skully42 · Jan 21, 2012 at 02:04 PM 0
Share

hey i will try this out later and Aaron_Lewis al least these people are trying to help you just gave up

avatar image skully42 · Jan 21, 2012 at 02:29 PM 0
Share

hey the zombie still didnt kill me i dont know whats going my prefabs kill me

avatar image doomprodigy · Jan 22, 2012 at 09:13 PM 0
Share

@OrangeLightning & @skully42 I haven't given up. Your not providing anything. It will be a fault with your AI Code or something else, not your spawner. If your creating an enemy via instantiating your creating it, no matter what method. Your not giving any help towards us. I do not really have a mouth on me. But after a few people posting spawners people saying "here is a new spawner" haven't really realised the question and the issue. Post the AI Code and I will see if I (and others) can find something in it that would cause an issue with getting itself cloned or just in general.

Show more comments
avatar image
0

Answer by dinneenio · Mar 12, 2014 at 12:32 PM

Add this script to your enemy

 var enemyHealth : float = 10;
 var RecieveDamage : boolean;
 var DestroyAfterTime : float = 30;
 var DestroyAfterTimeRandomization : float = 0;
 @HideInInspector
 var countToDie : float;
 var playerDist : int;
 var playerCapsule : GameObject;
 var Attacking : boolean;
 
 
 
 
 
 function Start()
 {
     playerCapsule = GameObject.FindGameObjectWithTag("Player");
     Attacking = false; 
     
 }
 
 function Awake()
 {
     DestroyAfterTime += Random.value * DestroyAfterTimeRandomization;
 }
 
 function Update()
 {
     playerDist = Vector3.Distance(playerCapsule.transform.position, transform.position);
     
     if(playerDist <= 2)
     {
         if(!Attacking)
         {
             Invoke("ApplyDamage", 1);
         }    
     }
 }
 
     
 function ApplyDamage()
 {
     playerCapsule.SendMessage("minusHealth");
     Attacking = false;
 }
 
 /////////////////////////////and this one to your player and they will kill you no problem. :) \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

 var playerHealth : int;
 var playerScript : PlayerMovementScript;
 var player : Rigidbody;
 
 
 
 function Start () 
 {
     playerHealth = 100;
 }
 
 function Update () 
 {
     if(playerHealth <= 0)
     {
         playerHealth = 0;
         Death();
     }
          
 }
 
 function Death()
 {
     print("You Are Dead");
     rigidbody.isKinematic = true;
     rigidbody.freezeRotation = false;
     playerScript.enabled = false;
     
 }
 
 function minusHealth()
 {
     playerHealth -=1;
 }
 
Comment
Add comment · 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

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

10 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

Related Questions

Multiple Cars not working 1 Answer

Mob spawn and start comming to me 1 Answer

Setting Spawn Rotation correct 1 Answer

Zombie attack script help 1 Answer

Help With Zombie Survival? 2 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