Im adjusting the survival shooter health script so that my pick up item adds health. There is a parsing error and some unexpected symbols but im sure its because it says that “public” in take damage and “void” in death is an unexpected symbol in one case and in the other it says it cannot be used in this context. Also it says that “Death ()” in Take Damage doesnt exist in the current context, please help!
Player Health:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class PlayerHealth : MonoBehaviour
{
public int startingHealth = 100;
public int currentHealth;
public int maxHealth = 100;
public Slider healthSlider;
public Image damageImage;
public AudioClip deathClip;
public float flashSpeed = 5f;
public Color flashColour = new Color(1f, 0f, 0f, 0.1f);
Animator anim;
AudioSource playerAudio;
PlayerMovement playerMovement;
PlayerShooting playerShooting;
bool isDead;
bool damaged;
void Awake ()
{
anim = GetComponent <Animator> ();
playerAudio = GetComponent <AudioSource> ();
playerMovement = GetComponent <PlayerMovement> ();
playerShooting = GetComponentInChildren <PlayerShooting> ();
currentHealth = startingHealth;
}
void Start ()
{
startingHealth = maxHealth;
}
void Update ()
{
healthSlider.value = currentHealth;
if(damaged)
{
damageImage.color = flashColour;
}
else
{
damageImage.color = Color.Lerp (damageImage.color, Color.clear, flashSpeed * Time.deltaTime);
}
damaged = false;
}
public void AddHealth (int amount)
{
currentHealth += amount;
if (currentHealth <= 0)
{
currentHealth = 0;
{
if (currentHealth >= maxHealth)
{
currentHealth = maxHealth;
}
}
public void TakeDamage (int amount)
{
damaged = true;
currentHealth -= amount;
playerAudio.Play ();
if (currentHealth <= 0 && !isDead)
{
Death ();
}
}
void Death ()
{
isDead = true;
playerShooting.DisableEffects ();
anim.SetTrigger ("Die");
playerAudio.clip = deathClip;
playerAudio.Play ();
playerMovement.enabled = false;
playerShooting.enabled = false;
}
public void RestartLevel ()
{
Application.LoadLevel (Application.loadedLevel);
}
}
`
There are no errors on my pick up object but in case it is affecting my player health script i decided to post it up.
PlayerAddhealth:
using UnityEngine;
using System.Collections;
public class PlayerAddHealth : MonoBehaviour
{
public int addHealth = 10;
public int startingHealth = 100;
public int currentHealth;
GameObject healthpickup;
GameObject player;
PlayerHealth playerHealth;
void Awake ()
{
healthpickup = GameObject.FindGameObjectWithTag ("healthpickup");
playerHealth = player.GetComponent<PlayerHealth> ();
}
void OnTriggerEnter (Collider other)
{
if(other.gameObject.tag == healthpickup)
{
playerHealth.AddHealth (addHealth);
Destroy (healthpickup);
}
}
}