Exemplo n.º 1
0
 static public void DefaultAmmoType(AmmoTypeInfo info)
 {
     info.baseDamage      = 10.0f;
     info.caliber         = 0.2f + Random.value * 0.6f;
     info.caliberToLength = 2.0f + 4.0f * Random.value;
     info.effectType      = EffectType.None;
 }
Exemplo n.º 2
0
    public void SpawnProjectile()
    {
        GameObject projectile = projectilePool.GetNext();

        //Scaling constants for unit compatibility
        float projScale     = 0.5f;    //Projectile size scale
        float velocityScale = 1.5f;    //Muzzle velocity scale

        Vector3        shootFrom = GetBarrel().position;
        ProjectileInfo info      = projectile.GetComponent <ProjectileInfo>();

        info.startPosition = shootFrom;
        info.weaponInfo    = weaponInfo;

        AmmoTypeInfo ammoTypeInfo = info.GetComponent <AmmoTypeInfo>();

        //Projectile dimensions
        float projDiameter = ammoTypeInfo.caliber * projScale;
        float projLength   = projDiameter * (ammoTypeInfo.caliberToLength * 2.0f);

        projectile.transform.position   = shootFrom;
        projectile.transform.localScale = new Vector3(projDiameter, projLength, projDiameter);

        Rigidbody body = projectile.GetComponent <Rigidbody>();

        Vector3 direction = new Vector3(0, 0, weaponInfo.muzzleVelocity * velocityScale);

        projectile.transform.rotation = gameObject.transform.rotation * Quaternion.Euler(90.0f, 0.0f, 0.0f);
        body.velocity = gameObject.transform.rotation * direction;

        AudioSource audioSource = gameObject.GetComponent <AudioSource>();
        AudioClip   fireClip    = ammoTypeInfo.soundOnFire;

        audioSource.PlayOneShot(fireClip);
    }
Exemplo n.º 3
0
    void OnCollisionEnter(Collision collision)
    {
        //To do:  If hit enemy: calculate damage from weaponInfo, ammoTypeInfo, and enemy stats
        //  On all collision: set projectile to inactive
        //  'startPosition' is for determining effect of damage falloff
        GameObject target = collision.gameObject;

        AmmoTypeInfo ammoType = gameObject.GetComponent <AmmoTypeInfo>();
        AudioClip    hitClip  = null;

        if (target.tag == "Enemy")
        {
            TestTarget testTarget = target.GetComponent <TestTarget>();

            if (testTarget != null)
            {
                testTarget.ResetTarget();
            }

            hitClip = ammoType.soundOnHitEnemy;
        }
        else
        {
            hitClip = ammoType.soundOnHitWall;
        }

        TerminateWithSound(hitClip);
    }