Hi I am new to coding and want to activate a rag-doll if the enemy's health value = 0, unfortunately in my code it says Cannot assign to Death because its a method group. If anyone can help my solve this issue I would greatly appreciate it. The code is down below( it is in the "void OnEnable()" section):
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();
health = 40;
capsuleCollider = GetComponent();
anim = GetComponent();
}
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();
if (GetComponent() != null)
{
myCollider = GetComponent();
}
if (GetComponent() != null)
{
myRigidbody = GetComponent();
}
}
void ActivateRagdoll()
{
if (myRigidbody != null)
{
myRigidbody.isKinematic = false;
myRigidbody.useGravity = true;
}
if (myCollider != null)
{
myCollider.isTrigger = false;
myCollider.enabled = true;
}
}
}
↧