Beispiel #1
0
    /*
     * Activates cooldown flag to prevent units from firing between cooldowns
     * deals damage to the target
     * resets the cooldown flag to false after the atk speed duration has passed
     */
    IEnumerator Fire()
    {
        cooldown = true;
        bool    shouldTarget = false;
        Vector3 laserTarget  = Vector3.zero;

        if (MotherTarget != null)
        {
            Debug.Log(gameObject.name);
            laserTarget = MotherTarget.transform.position;
            MotherTarget.TakeDamage(stats.Damage);
            shouldTarget = true;
        }
        else if (target != null)
        {
            laserTarget = target.transform.position;
            target.TakeDamage(stats.Damage);
            shouldTarget = true;
        }

        if (shouldTarget)
        {
            System.Random rng     = new System.Random();
            float         xOffset = rng.Next(MinimumLaserOffset, MaximumLaserOffset) + laserTarget.x;
            float         yOffset = rng.Next(MinimumLaserOffset, MaximumLaserOffset) + laserTarget.y;
            float         zOffset = rng.Next(MinimumLaserOffset, MaximumLaserOffset) + laserTarget.z;
            laserTarget.Set(xOffset, yOffset, zOffset);
            StartCoroutine(LaserAnimation(laserTarget));
        }

        yield return(new WaitForSeconds(stats.AtkSpeed));

        cooldown = false;
    }