Beispiel #1
0
    /// <summary>
    /// Creates a red floating label over the enemy's head to signify the damage it took
    /// </summary>
    /// <param name="damage"></param>
    public void CreateDamagePopNumber(int damage)
    {
        //By how much the number can be randomly offset horizontally
        const float  POP_NUMBER_RANDOM_X_OFFSET = 1f;
        const string INFINITY_SYMBOL            = "\x221E";

        //Don't show pop-up if no damage was taken
        if (damage <= 0)
        {
            return;
        }

        //Calculate offsets
        float verticalOffset   = 1f;
        float horizontalOffset = RandomValueBetween.Symetrical(POP_NUMBER_RANDOM_X_OFFSET).Pick();

        //Spawn object
        TextMeshPro instance = Commons.InstantiateInCurrentLevel(
            original: DamageTextPrefab,
            position: transform.position + Vector3.up * verticalOffset + Vector3.right * horizontalOffset
            ).GetComponent <TextMeshPro>();

        //Set damage text
        string damageText = damage.ToString();

        if (damage >= 10000)
        {
            damageText = INFINITY_SYMBOL;
        }

        instance.text = $"-{damageText}";
    }
Beispiel #2
0
    protected override void OnFire(WeaponInstance instance, WeaponShooterBase shooter, Vector2 direction)
    {
        for (int i = 0; i < BlastCount; i++)
        {
            Projectile newAmmo = Instantiate(
                original: Ammunition,
                position: shooter.GetProjectilesSpawnPoint(),
                rotation: Quaternion.identity
                );

            //Rotates the bullet random amount
            RandomValueBetween randomAngle = new RandomValueBetween(-MaxAngle / 2, MaxAngle / 2);
            int angle = randomAngle.PickInt();
            newAmmo.Direction = direction;
            newAmmo.transform.Rotate(angle);

            WeaponFireHurtbox hurtbox = newAmmo.GetComponentInChildren <WeaponFireHurtbox>();
            hurtbox.Shooter = shooter;
            hurtbox.Weapon  = instance;
        }
    }