*i seem to have a working script so far, the only errors i have seen is a “cs1041: identifier expected” at lines 45,61,77,93.
anyone know how to fix it? C#*
*FIXED
using UnityEngine;
using System.Collections;
public class HealthController : MonoBehaviour {
public GameObject deathHandler;
public float maxHealth = 100;
public float hitDamage = 3;
public float healingSpeed = 2;
public GameObject hitParticles;
public GameObject MGBullet;
public GameObject Bullet;
public GameObject Missile;
public GameObject Pellet;
public AudioClip hitSound;
[HideInInspector]
public float health;
public float normalizedHealth { get { return health / maxHealth; } }
// Use this for initialization
void OnEnable () {
health = maxHealth;
}
// Update is called once per frame
void Update () {
if (Time.deltaTime == 0 || Time.timeScale == 0)
return;
if (health > 0)
health += Time.deltaTime * healingSpeed;
health = Mathf.Clamp(health, 0, maxHealth);
}
void OnHit (MGBullet @MGBullet) {
health -= 6;
health = Mathf.Clamp(health, 0, maxHealth);
if (hitParticles) {
GameObject particles = Instantiate(
hitParticles,
MGBullet.hit.point,
Quaternion.LookRotation(-MGBullet.direction)
) as GameObject;
particles.transform.parent = transform;
}
if (hitSound) {
AudioSource.PlayClipAtPoint(hitSound, MGBullet.hit.point, 0.6f);
}
}
void OnHit (Bullet @Bullet) {
health -= 10;
health = Mathf.Clamp(health, 0, maxHealth);
if (hitParticles) {
GameObject particles = Instantiate(
hitParticles,
Bullet.hit.point,
Quaternion.LookRotation(-Bullet.direction)
) as GameObject;
particles.transform.parent = transform;
}
if (hitSound) {
AudioSource.PlayClipAtPoint(hitSound, Bullet.hit.point, 0.6f);
}
}
void OnHit (Pellet @Pellet) {
health -= 9;
health = Mathf.Clamp(health, 0, maxHealth);
if (hitParticles) {
GameObject particles = Instantiate(
hitParticles,
Pellet.hit.point,
Quaternion.LookRotation(-Pellet.direction)
) as GameObject;
particles.transform.parent = transform;
}
if (hitSound) {
AudioSource.PlayClipAtPoint(hitSound, Pellet.hit.point, 0.6f);
}
}
void OnHit (Missile @Missile) {
health -= 100;
health = Mathf.Clamp(health, 0, maxHealth);
if (hitParticles) {
GameObject particles = Instantiate(
hitParticles,
Missile.hit.point,
Quaternion.LookRotation(-Missile.direction)
) as GameObject;
particles.transform.parent = transform;
}
if (hitSound) {
AudioSource.PlayClipAtPoint(hitSound, Missile.hit.point, 0.6f);
}
}
}
_-----------------------------------------------------------
EDIT
i figured out the class thing, but i have a different error now, it thinks that missile, MGBullet, and Bullet are types, but Pellet is a field. how do i get them to be fields?