public void ProjectileTimeTest()
    {
        ShotHelper shot = new ShotHelper()
        {
            dmg        = 10,
            range      = 10,
            shot_speed = 10
        };

        float timer = shot.range / shot.shot_speed;

        Assert.IsTrue(timer == shot.getTimer());
    }
Exemple #2
0
    void RigidbodyShot()
    {
        Transform camera = cameraMovement.transform; //Shoot from camera, not gun

        GunObject gun = gunHandler.gun;

        if (gun.rigidbodyBullet == null || gunHandler.BulletPool == null)
        {
            return;
        }
        Vector3 spawnPos = gunHandler.bulletSpawn.transform.position;
        Vector3 shotDir  = getShotDir(bulletSpread);
        Vector3 worldDir = camera.TransformDirection(shotDir);

        //Get bullet from pool
        PooledObject bullet = gunHandler.BulletPool.get();

        bullet.transform.position = spawnPos;
        bullet.transform.rotation = Quaternion.LookRotation(worldDir);

        if (bullet as DamageObject)
        {
            (bullet as DamageObject).Damage = gun.bulletDamage;
        }

        Rigidbody bulletBody = null;

        if ((bulletBody = bullet.transform.GetComponent <Rigidbody>()) == null)
        {
            return;
        }

        ShotHelper shotHelper = null;

        if ((shotHelper = bullet as ShotHelper) != null)
        {
            shotHelper.Initialize(bulletBody, gun, CreateImpact);
        }

        float force = gun.initialForce;

        if (gunHandler.gun.canFireWhileDelayed)
        {
            force *= DelayPercent();
        }

        bulletBody.AddForce(worldDir * force, ForceMode.Impulse);
    }