- Home /
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);
}
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.
i looked and when they do spawn it says clone right after
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;
}
}
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
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.
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
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.
Your spawner is not the problem then. It is something in your AI Code.
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
Omg, Can you all not see it has nothing to do with his spawner. Idiots I tell you...
@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.
hey i will try this out later and Aaron_Lewis al least these people are trying to help you just gave up
hey the zombie still didnt kill me i dont know whats going my prefabs kill me
@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.
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;
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613063141im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
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