Esempio n. 1
0
 /// <summary>
 /// when soldier collides with enemy- stop moving to path
 /// </summary>
 /// <param name="collision">enemy's collision</param>
 private void OnCollisionEnter2D(Collision2D collision)
 {
     if (collision.collider.tag != this.tag && (collision.collider.tag.Contains("soldier") || collision.collider.tag.Contains("miner")))
     {
         stopedWalking = true;
         walk.StopMovingToPath(true);
     }
 }
Esempio n. 2
0
    void FixedUpdate()
    {
        if (targetChosen)
        {
            if (resource != null)
            {
                float h = animator.GetFloat("horizontal");
                if (h > 0 && !facingRight)
                {
                    Flip();
                }

                else if (h < 0 && facingRight)
                {
                    Flip();
                }



                MoveToPath();
            }
            else
            {
                isMoving = false;
            }


            if (!isMoving)
            {
                animator.SetBool("move", false);
                targetChosen = false;
                CancelInvoke();
            }

            if (reachedEndOfPath)
            {
                isMoving     = false;
                targetChosen = false;
                CancelInvoke();
            }
        }
        if (this.resource != null && this.resource.GetComponent <Resource>().occupied)
        {
            if (walk != null)
            {
                walk.StopMovingToPath(false);
            }

            LookForResorces(res);
        }
    }
Esempio n. 3
0
    /// <summary>
    /// when collides with resource- start to mine.
    /// </summary>
    /// <param name="collision"> resource's collison </param>
    private void OnCollisionEnter2D(Collision2D collision)
    {
        string res = "gold";

        if (collision.collider.tag == res || collision.collider.tag == "first stage of the building")
        {
            this.gameObject.GetComponent <Animator>().SetBool("mine", true);
            stopedWalking = true;
            if (walk != null)
            {
                walk.StopMovingToPath(true);
            }
            Debug.Log("OnCollisionEnter2D " + collision.collider.name);
        }
    }