Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
Sign in to follow this  

SendMessage ApplyDamage has no receiver!


help me to fix that error

SendMessage ApplyDamage has no receiver!
UnityEngine.Component:SendMessage(String, Object)
NewZombieAI:Update() (at Assets/New folder (9)/NewZombieAI.cs:83)


This is my NewZombie cs File



    using UnityEngine;
    using System.Collections;
    public class NewZombieAI : MonoBehaviour {
        Transform target; //the enemy's target
    public float  moveSpeed= 3; //move speed
    public float rotationSpeed= 3; //speed of turning
    public float attackRange= 3; // distance within which to attack
    public float chaseRange= 10; // distance within which to start chasing
    public float giveUpRange= 20; // distance beyond which AI gives up
        public float attackRepeatTime = 1.5f; // delay between attacks when within range
    public GameObject anim;
    public float  maximumHitPoints= 5.0f;
    public float hitPoints= 5.0f;
    public GameObject Zombie_New;
    //public Transform 
    AudioClip attack;
        private bool chasing= false;
        private float attackTime;
        bool  checkRay = false;
    public string idleAnim = "idle";
    public    string walkAnim = "walk";
    public    string attackAnim = "attack"; 
        int dontComeCloserRange = 2;
        private Transform myTransform; //current transform data of this enemy
        void  Awake (){
            myTransform = transform; //cache transform data for easy access/preformance
        ///zombie_New.anim.GetComponent.<Animation>().wrapMode = WrapMode.Loop;
        Zombie_New.GetComponent<Animation> (). wrapMode = WrapMode.Loop;
         Zombie_New.GetComponent<Animation> ().wrapMode = WrapMode.Once;
        //anim.GetComponent.<Animation>()[attackAnim].wrapMode = WrapMode.Once;
        Zombie_New.GetComponent<Animation> ()[attackAnim].layer = 2;
            //anim.GetComponent.<Animation>()[attackAnim].layer = 2;
        Zombie_New.GetComponent<Animation> ().Stop();
        void  Start (){
            target = GameObject.FindWithTag("Player").transform;
        void  Update (){
            // check distance to target every frame:
        float distance = (target.position - myTransform.position).magnitude;
            if (distance < dontComeCloserRange){
                moveSpeed = 0;
            Zombie_New.GetComponent<Animation> ().Play(idleAnim);
                Zombie_New.GetComponent<Animation> ().CrossFade(idleAnim);
                moveSpeed = Random.Range(2, 3);
                Zombie_New.GetComponent<Animation> ().CrossFade(walkAnim);
            if (chasing) {    
                //move towards the player
                myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
                //rotate to look at the player
                myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
            transform.eulerAngles = new Vector3(0.0f, transform.eulerAngles.y, 0.0f); 
                // give up, if too far away from target:
                if (distance > giveUpRange) {
                    chasing = false;
                // attack, if close enough, and if time is OK:
                if (distance < attackRange && Time.time > attackTime) {
                    //anim.GetComponent.<Animation>()[attackAnim].speed = 4.0f;
                    Zombie_New.GetComponent<Animation> ()[attackAnim].speed = 1.0f;
                    Zombie_New.GetComponent<Animation> ().CrossFade(attackAnim);
                target.SendMessage( "ApplyDamage", maximumHitPoints);
                    attackTime = Time.time + attackRepeatTime;
                    //GetComponent.<AudioSource>().PlayOneShot(attack, 1.0f / GetComponent.<AudioSource>().volume);

            } else {
                // not currently chasing.
                //anim.GetComponent.<Animation>() [idleAnim].speed = 4;
            Zombie_New.GetComponent<Animation> ()[idleAnim].speed = 4;
                Zombie_New.GetComponent<Animation> ().CrossFade(idleAnim);
            // start chasing if target comes close enough
                if (distance < chaseRange) {
                    chasing = true;
        void  OnDrawGizmosSelected (){
            Gizmos.color = Color.yellow;
            Gizmos.DrawWireSphere (transform.position, attackRange);
            Gizmos.color = Color.red;
            Gizmos.DrawWireSphere (transform.position, chaseRange);

Please login or register to see this attachment.

Share this post

Link to post
Share on other sites

0 answers to this question

Recommended Posts

  • 0



     target.SendMessage( "ApplyDamage", maximumHitPoints);


   target.SendMessage( "ApplyDamage", maximumHitPoints, SendMessageOptions.DontRequireReceiver);

  • Like 2

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...