Beispiel #1
0
    private void FireWeaponAtTarget()
    {
        timeSinceLastShot -= Time.deltaTime;
        if (!target)
        {
            return;
        }
        Vector3 dir  = target.transform.position - transform.position;
        float   diff = dir.magnitude;

        //Debug.Log("distance: " + diff + ". AtkRng: " + attackRange);
        if (diff <= attackRange && timeSinceLastShot <= 0)
        {
            sh.SpikeLoudnessDueToAttack();
            AudioSource.PlayClipAtPoint(selectedFiringSound, transform.position);
            selectedFiringSound = SelectSoundFromArray(firingSounds);
            float      zAng   = Vector3.SignedAngle(Vector2.up, dir, Vector3.forward);
            Quaternion rot    = Quaternion.Euler(0, 0, zAng);
            GameObject bullet = Instantiate(weaponPrefab, transform.position + (dir * bulletOffset), rot) as GameObject;
            bullet.GetComponent <Rigidbody2D>().velocity = weaponSpeed * bullet.transform.up;
            DamageDealer dd = bullet.GetComponent <DamageDealer>();
            dd.SetDamage(weaponDamage);
            dd.SetAttackSource(gameObject);
            Destroy(bullet, weaponLifetime);
            timeSinceLastShot = timeBetweenShots;
        }
    }
Beispiel #2
0
    private void RpcDisplaySimAttackOnClients(Vector3 pos, Quaternion rot)
    {
        GameObject bullet = Instantiate(weaponPrefab, pos, rot) as GameObject;

        bullet.GetComponent <Rigidbody2D>().velocity = bullet.transform.up * weaponSpeed;
        DamageDealer dd = bullet.GetComponent <DamageDealer>();

        dd.Simulated = true;
        dd.SetDamage(0);
        dd.SetAttackSource(gameObject);
        Destroy(bullet, weaponLifetime);
    }
Beispiel #3
0
    public override void AttackCommence()
    {
        if (timeSinceLastAttack < 0 && energy.GetCurrentEnergy() >= energyCost)
        {
            sh.SpikeLoudnessDueToAttack();
            AudioSource.PlayClipAtPoint(selectedFiringSound, transform.position);
            GameObject shell = Instantiate(projectilePrefab, transform.position + (transform.up * offset), transform.rotation) as GameObject;
            shell.GetComponent <Rigidbody2D>().velocity = shell.transform.up * weaponSpeed;
            DamageDealer dd = shell.GetComponent <DamageDealer>();
            dd.SetAttackSource(transform.root.gameObject);
            dd.SetDamage(weaponDamage);

            Destroy(shell, weaponLifetime);

            timeSinceLastAttack = timeBetweenAttacks;
            energy.ModifyCurrentEnergy(-1 * energyCost);
        }
    }