i am trying to make it so if the object is collided with the another object enough times a bool from another script will activate. but the following error occurs with the enemydestroyed.enedeath:
“an object reference is required for the nonstatic field method or property”
My script
using UnityEngine;
using System.Collections;
public class swordCollideWithEnemybasic : MonoBehaviour {
public int enehealth = 5;
public int knockback = 1;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void OnCollisionEnter (Collision hit) {
if (enehealth > 0)
if (hit.gameObject.name == "sword");
gameObject.renderer.material.color = Color.red;
StartCoroutine (turngreyDelayed ());
if (enehealth <= 0)
enemydestroyed.enedeath = true;
}
IEnumerator turngreyDelayed() {
yield return new WaitForSeconds(0.2f);
gameObject.renderer.material.color = Color.grey;
int addDamage = enehealth;
int newDamage = enehealth - 1;
enehealth = newDamage;
Debug.Log(enehealth);
transform.Translate (0,0,knockback * Time.deltaTime);
}
}
another script:
using UnityEngine;
using System.Collections;
public class enemydestroyed : MonoBehaviour {
public bool enedeath = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnCollisionEnter (Collision hit) {
if (enedeath = true);
if (hit.gameObject.name == "sword")
gameObject.renderer.material.color = Color.red;
StartCoroutine (turngreyDelayedDestroy());
}
IEnumerator turngreyDelayedDestroy() {
yield return new WaitForSeconds(0.2f);
gameObject.renderer.material.color = Color.white;
yield return new WaitForSeconds(0.1f);
Destroy (gameObject);
//^insert animation"//
}
}