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:
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.
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.
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;
}