Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Need help with AI error

Discussion in 'Editor & General Support' started by Enrothian_Empire, Jul 23, 2014.

  1. Enrothian_Empire

    Enrothian_Empire

    Joined:
    Apr 29, 2014
    Posts:
    5
    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)
    <Shoot>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.
     
  2. marcfielding

    marcfielding

    Joined:
    Aug 1, 2013
    Posts:
    34
    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?
     
  3. Enrothian_Empire

    Enrothian_Empire

    Joined:
    Apr 29, 2014
    Posts:
    5
    //damage by Calculation
    if (Random.Range(0, 100) <=hitChance)
    {
    target.SendMessage("ApplyDamage", Random.Range(minDamage, maxDamage));
    }
     
  4. marcfielding

    marcfielding

    Joined:
    Aug 1, 2013
    Posts:
    34
    Ok getting there where is target assigned/instantiated? As in where is the variable created
     
  5. Enrothian_Empire

    Enrothian_Empire

    Joined:
    Apr 29, 2014
    Posts:
    5
    Do you mean where I stuck the player and enemy?
     
  6. marcfielding

    marcfielding

    Joined:
    Aug 1, 2013
    Posts:
    34
    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.
     
  7. Enrothian_Empire

    Enrothian_Empire

    Joined:
    Apr 29, 2014
    Posts:
    5
    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?
    Capsule.png
     
    Last edited: Jul 25, 2014