示例#1
0
 // Update is called once per frame
 void Update()
 {
     if (new_target)
     {
         new_target       = false;
         target_entity    = null;
         targeting_entity = false;
         GetComponent <unit_sounds>().Play("Acknowledge");
         animator.SetTrigger("Walk");
         targeting      = true;
         animator.speed = 1;
     }
     if (target_entity)
     {
         animator.SetTrigger("Walk");
         targeting        = true;
         targeting_entity = true;
         target           = target_entity.transform.position;
         target.z         = orc_z;
     }
     if (targeting_entity && target_entity == null)
     {
         targeting_entity = false;
         targeting        = false;
     }
     if (targeting)
     {
         Vector3 direction_vector = (target - this.transform.position).normalized;
         float   direction        = Vector3.Dot(Vector3.up, direction_vector);
         animator.SetFloat("Direction", direction);
         if (target.x < this.transform.position.x)
         {
             this.transform.localScale = new Vector3(-1, 1, 1);
         }
         else
         {
             this.transform.localScale = new Vector3(1, 1, 1);
         }
         float   old_distance = (this.transform.position - target).magnitude;
         Vector3 displacement = direction_vector * speed * Time.deltaTime;
         //			Debug.Log ("Distance: "+old_distance+" Displacement: "+displacement.magnitude);
         if (old_distance > displacement.magnitude)
         {
             this.transform.position += displacement;
         }
         if (old_distance <= displacement.magnitude)
         {
             this.transform.position = target - (direction_vector * (max_distance / 2));
         }
         if (old_distance <= displacement.magnitude + max_distance)
         {
             targeting      = false;
             animator.speed = 0;
             animator.Play("Walking", 0, 0);
         }
     }
     //		this.transform.position = new Vector3 (transform.position.x, transform.position.y, transform.position.y);
 }
示例#2
0
    void OnCollisionStay2D(Collision2D coll)
    {
        entity_ex03 enemy = coll.gameObject.GetComponent <entity_ex03>();

        if (enemy && attack > 0 && enemy.alliance != alliance && attack_timer >= attack_interval)
        {
            attack_timer      = 0.0f;
            enemy.hit_points -= attack;
            Debug.Log(enemy.unit_name + " [" + enemy.hit_points + "/" + enemy.max_hp + "] has been attacked.");
        }
    }
示例#3
0
 // Use this for initialization
 void Start()
 {
     animator         = GetComponent <Animator>();
     orc_z            = this.transform.position.z;
     new_target       = false;
     targeting        = false;
     target_entity    = null;
     targeting_entity = false;
     animator.SetFloat("Direction", -1);
     // Add to manager
     // orc_manager_ex03.instance.Add (this);
 }
示例#4
0
    void OnCollisionEnter2D(Collision2D coll)
    {
        entity_ex03  enemy   = coll.gameObject.GetComponent <entity_ex03>();
        footman_ex01 footman = GetComponent <footman_ex01>();
        orc_ex02     orc     = GetComponent <orc_ex02>();

        if (footman && enemy && enemy.alliance != alliance)
        {
            footman.target_entity = enemy;
        }
        if (orc && enemy && enemy.alliance != alliance)
        {
            orc.target_entity = enemy;
        }
    }
 // Use this for initialization
 void Start()
 {
     dead             = false;
     animator         = GetComponent <Animator>();
     footman_z        = this.transform.position.z;
     new_target       = false;
     targeting        = false;
     target_entity    = null;
     targeting_entity = false;
     animator.SetFloat("Direction", -1);
     // Add to manager
     if (footman)
     {
         manager_ex01.instance.Add(this);
         manager_orcs.instance.AddToHitList(this);
     }
     if (orc)
     {
         manager_orcs.instance.Add(this);
     }
 }
 public bool wereCrushed(entity_ex03 victim)
 {
     return(victim == null);
 }
    // Update is called once per frame
    void Update()
    {
        if (dead)
        {
            return;
        }
        if (new_target)
        {
            new_target       = false;
            target_entity    = null;
            targeting_entity = false;
            GetComponent <unit_sounds>().Play("Acknowledge");
            animator.Play("Walking", 0, 0);
            animator.SetTrigger("Walk");
            animator.speed = 1;
            targeting      = true;
        }
        if (target_entity)
        {
            targeting        = true;
            targeting_entity = true;
            target           = target_entity.transform.position;
            target.z         = footman_z;
        }
        if (targeting_entity && target_entity == null)
        {
            targeting_entity = false;
            targeting        = false;
        }
        if (targeting)
        {
            Vector3 direction_vector = (target - this.transform.position).normalized;
            float   direction        = Vector3.Dot(Vector3.up, direction_vector);
            animator.SetFloat("Direction", direction);
            if (target.x < this.transform.position.x)
            {
                this.transform.localScale = new Vector3(-1, 1, 1);
            }
            else
            {
                this.transform.localScale = new Vector3(1, 1, 1);
            }
            float   old_distance = (this.transform.position - target).magnitude;
            Vector3 displacement = direction_vector * speed * Time.deltaTime;
//			Debug.Log ("Distance: "+old_distance+" Displacement: "+displacement.magnitude);
            if (old_distance > displacement.magnitude)
            {
                this.transform.position += displacement;
            }
            if (old_distance <= displacement.magnitude)
            {
                this.transform.position = target - (direction_vector * (max_distance / 2));
            }
            if ((old_distance <= displacement.magnitude + max_distance) && target_entity == null)
            {
                targeting = false;
            }
        }
        if (!targeting)
        {
            animator.speed = 0;
            animator.Play("Walking", 0, 0);
        }
        else
        {
            animator.speed = 1;
            if (target_entity)
            {
                float            calculated = attack_distance;
                CircleCollider2D coll       = GetComponent <CircleCollider2D>();
                if (coll)
                {
                    calculated += coll.radius;
                }
                coll = target_entity.GetComponent <CircleCollider2D>();
                if (coll)
                {
                    calculated += coll.radius;
                }
                Vector3 target_entity_position = new Vector3(target_entity.transform.position.x, target_entity.transform.position.y, transform.position.z);
//				Debug.Log ((target_entity_position - transform.position).magnitude + " < " + calculated);
                if ((target_entity_position - transform.position).magnitude < calculated)
                {
                    animator.SetTrigger("Attack");
                    GetComponent <unit_sounds>().Attack();
                    return;
                }
            }
            animator.SetTrigger("Walk");
        }
    }