Hello!
I am a beginning programmer, and have started out by making a small top down shooter. I’ve got most of the basic components done but have gotten stuck on one thing. I am trying to make it so that an enemy touches the player, it deals one damage, and explodes. The part I am stuck on is changing the player health variable, contained in the playerDeath script, which tells when to play the death animation, from within the damage scrip (which tells when to deal damage and how much.) I have looked at many a tutorial, even so far as to directly copy code (something I am not fond of doing, but keep getting errors, and all around not a functional script.
Below is my code so far, along with errors. (Please tell me if I need to be more specific or include more information.)
This is the playerKill script
Below is damage
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playerKill : MonoBehaviour {
public float health;
public Transform playerSpawn;
public GameObject playerVFX;
bool playerDead = false;
// Use this for initialization
void Start () {
}
IEnumerator killPlayer() {
Instantiate(playerVFX, playerSpawn.position, playerSpawn.rotation);
yield return new WaitForSeconds (0.1f);
Destroy (gameObject);
}
// Update is called once per frame
void Update () {
if (health <= 0 && playerDead == false) {
StartCoroutine ("killPlayer");
playerDead = true;
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class walkerDamage : MonoBehaviour {
public GameObject player;
private playerKill playerScript;
private float healthAccess;
// Use this for initialization
void Start () {
playerKill = player.GetComponent<playerKill> ();
healthAccess = playerKill.health;
}
// Update is called once per frame
void Update () {
}
}