I’m probably posting this in the wrong section, and I apologize.
My problem is with AI scripts. The error message is "
SendMessage ApplyDamage has no receiver!
UnityEngine.Component:SendMessage(String, Object)
c__Iterator1:MoveNext() (at Assets/AI4Enemies/Scripts/AIController.cs:343)"
I’m using several asset packages, AI4Enemies, Character System, Destero RPG System, Easy AI System, and Top Down.
I’ve tried applying capsule colliders to both the enemy’s weapon and the player, but when the enemy tries to attack, it pops up with that error.
SendMessage simply calls a function on the specified object , essentially you’re not passing the right object to that line of code. Could you post a code sample?
//damage by Calculation
if (Random.Range(0, 100) <=hitChance)
{
target.SendMessage(“ApplyDamage”, Random.Range(minDamage, maxDamage));
}
Ok getting there where is target assigned/instantiated? As in where is the variable created
Do you mean where I stuck the player and enemy?
Yeah where do you assign a value to target , it would be in the code where you assess where you’ve hit something or not.
This is about all I found in terms of damage/hitting.
public void AddLife(float life)
{
health += life;
}
public void ApplyDamage(float damage)
{
health -= damage;
fieldOfView = 360;
if (health <= 0)
{
StartCoroutine(CharacterDie());
}
else
{
StartCoroutine(CharacterHit());
//CharacterHit();
}
}
IEnumerator CharacterHit()
{
if (hitAnimation != “”)
{
isHit = true;
if (crossFadeAnimations)
{
animation.CrossFade(hitAnimation);
}
else
{
animation.Play(hitAnimation);
}
if (playSound)
{
hitSound.Play();
}
yield return new WaitForSeconds(0.4f);
isHit = false;
}
if (onHit != null)
{
AIEventArgs e = new AIEventArgs ();
e.name = gameObject.name;
e.health = health;
e.position = gameObject.transform.position;
e.rotation = gameObject.transform.rotation;
e.tag = gameObject.tag;
onHit(e);
}
}
IEnumerator CharacterDie()
{
if (!isDead)
{
isDead = true;
isAlive = false;
Debug.Log(“Play die”);
if (dieAnimation != “”)
{
if (crossFadeAnimations)
{
animation.CrossFade(dieAnimation);
}
else
{
animation.Play(dieAnimation);
}
}
if (playSound)
{
dieSound.Play();
}
yield return new WaitForSeconds(0.4f);
if (deathDelayTime == 0)
{
Destroy(this.gameObject);
}
else if (deathDelayTime > 0)
{
Destroy(this.gameObject, deathDelayTime);
}
if (onIsDying != null)
{
AIEventArgs e = new AIEventArgs();
e.name = gameObject.name;
e.health = health;
e.position = gameObject.transform.position;
e.rotation = gameObject.transform.rotation;
e.tag = gameObject.tag;
onIsDying(e);
}
}
That being said, I find it fails to see the player if the capsule’s Y position is changed to 0.5 instead of 0 (to put it in the centre of the enemy.) Would that pose a problem?