/// <summary> Shoots the given target.</summary>
    /// <param name="target"> Target for the Solider.</param>
    public void Shoot(Solider target)
    {
        if (!isMoving && canShoot)
        {
            if ((target.transform.position - transform.position).magnitude < Range)
            {
                float angle = 0;

                Vector2 diff = target.transform.position - transform.position;

                angle = Mathf.Atan2(diff.y, diff.x);

                angle *= Mathf.Rad2Deg;

                //Debug.Log( "Angle: " + angle );

                transform.rotation = Quaternion.Euler(0, 0, angle);

                //Random 50% change to hit

                float chance = Random.Range(0.0f, 100.0f);

                if (chance > 50)
                {
                    target.ApplyDamage(Damage + EffectedDamage);
                }

                canShoot = false;

                StartCoroutine(shotWaitTime());
            }
        }
    }
Exemplo n.º 2
0
    void OnCollisionEnter(Collision c)
    {
        Solider s = c.gameObject.GetComponent <Solider>();

        if (s != null)
        {
            switch (type)
            {
            case (TrapType.Bear):
                s.ApplyDamage(EffectAmount);
                break;

            case (TrapType.Snare):
                StartCoroutine(s.ApplyEffect(Solider.EffectType.Speed, EffectAmount, Duration));
                break;
            }
        }
    }
    /// <summary> Shoots the given target.</summary>
    /// <param name="target"> Target for the Solider.</param>
    public void Shoot( Solider target )
    {
        if ( !isMoving && canShoot )
        {

            if ( ( target.transform.position - transform.position ).magnitude < Range )
            {

                float angle = 0;

                Vector2 diff = target.transform.position - transform.position;

                angle = Mathf.Atan2( diff.y, diff.x );

                angle *= Mathf.Rad2Deg;

                //Debug.Log( "Angle: " + angle );

                transform.rotation = Quaternion.Euler( 0, 0, angle );

                //Random 50% change to hit

                float chance = Random.Range( 0.0f, 100.0f );

                if ( chance > 50 )
                {
                    target.ApplyDamage( Damage + EffectedDamage );
                }

                canShoot = false;

                StartCoroutine( shotWaitTime() );
            }
        }
    }