I have recently started to learn c# but I have encountered an error which I hope some of you will be able to help me with. We are developing a game in Unity5 and when the players health hits 0 the rag-doll function will kick in but unfortunately I cannot call death as it is a method group... Any ideas? Cheers. Here is the code(I commented it out so I could enter play mode in Unity because the error wasn't letting me in line 47 and 53):
using UnityEngine;
using System.Collections;
public class EnemyAI_Basic : MonoBehaviour
{
private EnemyAI_Basic enemyAI_Basic;
Animator controller;
float health;
Animator anim;
bool Alive = true;
public bool Dead = false;
int pointValue = 5;
private Collider myCollider;
private Rigidbody myRigidbody;
CapsuleCollider capsuleCollider;
void Start()
{
controller = GetComponentInParent<Animator>();
health = 40;
capsuleCollider = GetComponent<CapsuleCollider>();
anim = GetComponent<Animator>();
}
void Update()
{
if (!Dead)
{
anim.SetTrigger("Alive");
}
}
void Death()
{
Dead = true;
Alive = false;
capsuleCollider.isTrigger = true;
anim.SetTrigger("Dead");
Destroy(gameObject, 4f);
}
void OnEnable()
{
SetInitialReferences();
enemyAI_Basic.Death += ActivateRagdoll;
}
void OnDisable()
{
enemyAI_Basic.Death -= ActivateRagdoll;
}
void SetInitialReferences()
{
enemyAI_Basic = transform.root.GetComponent<EnemyAI_Basic>();
if (GetComponent<Collider>() != null)
{
myCollider = GetComponent<Collider>();
}
if (GetComponent<Rigidbody>() != null)
{
myRigidbody = GetComponent<Rigidbody>();
}
}
void ActivateRagdoll()
{
if (myRigidbody != null)
{
myRigidbody.isKinematic = false;
myRigidbody.useGravity = true;
}
if (myCollider != null)
{
myCollider.isTrigger = false;
myCollider.enabled = true;
}
}
}