I have 2 scripts one is a raycast script and one is a health script my error comes in on the raycast script on the code where i fire a raycast and access the void apply damage.
Health
public class HealthBear : MonoBehaviour {
public int health = 200;
private bool isDead = false;
public GameObject animal;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
}
public void ApplyDamage (int amount)
{
if (isDead)
return;
health -= amount;
if (health <= 0)
{
Death ();
}
}
public void Death ()
{
isDead = true;
Destroy (animal, 3f);
}
}
Raycast
using UnityEngine;
using System.Collections;
public class Raycast : MonoBehaviour
{
public float range;
private RaycastHit hit;
private Transform myTransform;
public float nextFire;
public float fireRate = 0.3f;
public HealthBear healthBear;
public int damage;
void Start ()
{
SetInitialreferences ();
}
void SetInitialreferences ()
{
myTransform = transform;
}
void FixedUpdate ()
{
CheckForInput ();
}
void CheckForInput ()
{
if (Input.GetButton("Fire1") && Time.time>nextFire)
{
Debug.DrawRay (myTransform.TransformPoint(0,0,1), myTransform.forward, Color.red, 3);
if(Physics.Raycast(myTransform.position, myTransform.forward, out hit, range))
{
Debug.Log (hit.transform.name);
healthBear.ApplyDamage (damage);
}
nextFire = Time.time+fireRate;
}
}
public void ApplyDamage (float damage)
{
}
}