- Home /
How to make enemys do damage and you dying etc
So I have a zombie arcade game in 3d, zombies can die, i do dmage, they fallow me, alls good. I Besides I need the zeds to be able to kill me as in 4 hits to me ends the game and switches to a GAME OVER scene. doesnt sound too complicated but ive been stuggling with this for the past 2 weeks. Also I would like if on each of the 4 hits blood goes on the screen and it gets redder (like in cod haha). Thanks anyone who helps! Heres my EnemyController Script:
using UnityEngine;
using System.Collections;
using UnityEngine.AI;
public class EnemyController : MonoBehaviour {
NavMeshAgent nav;
Transform player;
Animator Controller;
// Use this for initialization
void Awake () {
nav = GetComponent <NavMeshAgent> ();
player = GameObject.FindGameObjectWithTag ("Player").transform;
Controller = GetComponentInParent<Animator> ();
}
// Update is called once per frame
void Update () {
nav.SetDestination (player.position);
Controller.SetFloat ("speed", Mathf.Abs (nav.velocity.x + nav.velocity.z));
}
}
HERES MY GAME MANAGMENT SCRIPT IF YOU MAY NEED IT?
using System.Collections;
using UnityEngine;
public class GameManagment : MonoBehaviour {
public int round = 1;
int zombiesInRound = 10000000;
int zombiesSpawnedInRound = 0;
float zombieSpawnTimer = 0;
public Transform[] zombieSpawnPoints;
public GameObject zombieEnemy;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (zombiesSpawnedInRound < zombiesInRound)
{
if (zombieSpawnTimer > 2.1)
{
SpawnZombie ();
zombieSpawnTimer = 0;
}
else
{
zombieSpawnTimer += Time.deltaTime;
}
}
}
void SpawnZombie()
{
Vector3 randomSpawnPoint = zombieSpawnPoints [Random.Range (0, zombieSpawnPoints.Length)].position;
Instantiate(zombieEnemy, randomSpawnPoint, Quaternion.identity);
zombiesSpawnedInRound++;
}
}
Survival Shooter in Unity Learn section covers the subject of health and attack in a basic/decent way start from there. Anyway the logic behind the system is to have a script that holds a Health field on all entities (zombies/player) and you gonna need an attack method for player and one for the zombies. The Attack() should figures the target and reduce a porsion of the health from the target. For the zombies thats easy cause only the player is the target, but for the player it is a bit more tricky. Also you need a way to trigger the attack method, for the player through an Input, but for the zombies a more automated way is needed probably through the distance of the target. Lastly for the bloody screne it s quite easy you need to link the health of the player to an UI.image and change it depending on that(i think it is covered in the tutorial). Cheers.
Answer by Pitiedowl · Feb 08, 2017 at 09:07 AM
look up speed tutor on youtube he does some of these things and as for health and such its very difficult good luck
Your answer
Follow this Question
Related Questions
Canduct and movement of an enemy 0 Answers
Damage on prefab collision? 0 Answers
Enemy Damage to Player 0 Answers
Damage enemy cooldown 2 Answers
Player attacks once but the enemy takes double damages! 1 Answer