Exemplo n.º 1
0
    private BulletProjectile newProjectile()
    {
        GameObject       bulletObject = Instantiate(bulletPrefab, transform.position, Quaternion.identity) as GameObject;
        BulletProjectile bullet       = bulletObject.GetComponent <BulletProjectile>();

        return(bullet);
    }
Exemplo n.º 2
0
    public void ReturnBullet(BulletProjectile aBullet)
    {
        myExplotionEffect.transform.position = aBullet.transform.position;
        myExplotionEffect.Play();

        aBullet.transform.position = Vector3.zero;
        myActiveBullets.Remove(aBullet);
        myPassiveBullets.Add(aBullet);
        aBullet.gameObject.SetActive(false);
    }
Exemplo n.º 3
0
    void Fire()
    {
        GameObject       bulletObject = Instantiate(bulletPrefab, transform.position, transform.rotation) as GameObject;
        BulletProjectile bullet       = bulletObject.GetComponent <BulletProjectile>();

        bullet.owner = gameObject;
        bullet.GetComponent <Rigidbody2D>().velocity = truck.GetComponent <Rigidbody2D>().velocity;
        float bulletMagnitude = .5f;

        bullet.yVector = bulletMagnitude;
        Physics2D.IgnoreCollision(bullet.GetComponent <Collider2D>(), GetComponent <Collider2D>());
        Physics2D.IgnoreCollision(bullet.GetComponent <Collider2D>(), truck.GetComponent <Collider2D>());
        bullet.transform.parent = bullets.transform;
    }
Exemplo n.º 4
0
    public void CreateBullet(float xVelocity)
    {
        GameObject       bulletObject = Instantiate(bulletPrefab, transform.position, transform.rotation) as GameObject;
        BulletProjectile bullet       = bulletObject.GetComponent <BulletProjectile>();

        bullet.speed = bulletSpeed;
        bullet.owner = owner;
        bullet.GetComponent <Rigidbody2D>().velocity = owner.GetComponent <Rigidbody2D>().velocity;
        Physics2D.IgnoreCollision(bullet.GetComponent <Collider2D>(), owner.GetComponent <Collider2D>());
        float bulletMagnitude = .25f;

        bullet.yVector = bulletMagnitude;
        bullet.GetComponent <Rigidbody2D>().velocity = owner.GetComponent <Rigidbody2D>().velocity;
    }
Exemplo n.º 5
0
    private void CreateBullet(float angle, float yVector)
    {
        BulletProjectile bullet = newProjectile();

        bullet.speed   = speed;
        bullet.weapon  = this;
        bullet.yVector = yVector;
        bullet.GetComponent <Entity>().affinity = GetComponent <Entity>().affinity;
        float xMovement = player.GetComponent <Rigidbody2D>().velocity.magnitude;

        bullet.xVector = Mathf.Round(xMovement);
        OrientProjectile(bullet);
        bullet.RotateMe(angle);
    }
Exemplo n.º 6
0
    void InitializeBullets(GameManager aGameManager)
    {
        for (int bulletIndex = 0; bulletIndex < myBulletAmount; bulletIndex++)
        {
            BulletProjectile bullet = Instantiate(myBulletPrefab, Vector3.zero, Quaternion.identity, transform);
            //Sätter refernser till bulleten
            bullet.myBulletManager = this;
            bullet.myPlayer        = myPlayer;
            bullet.myGameManager   = aGameManager;

            myPassiveBullets.Add(bullet);
            bullet.gameObject.SetActive(false);
        }
    }
 void Shoot()
 {
     if (Time.time > nextFire && canFire == true && !isReloading && currentMagazine > 0)
     {
         currentMagazine--;
         nextFire = Time.time + fireRate;
         GameObject bullet = Instantiate(projectile, transform.position + transform.forward * 2, Quaternion.identity) as GameObject;
         Physics.IgnoreCollision(gameObject.GetComponent <CapsuleCollider>(), bullet.GetComponent <SphereCollider>());
         BulletProjectile bulletScript = bullet.GetComponent <BulletProjectile>();
         if (bulletScript != null)
         {
             bulletScript.setDamage(damage);
         }
         bullet.GetComponent <Rigidbody>().AddForce(transform.forward * 1000);
     }
 }
Exemplo n.º 8
0
    private void CreateBullet(Vector3 origin)
    {
//		AudioSource.PlayClipAtPoint(soundClip, transform.position);
        BulletProjectile bullet = newProjectile();

        bullet.speed  = speed;
        bullet.weapon = this;
        bullet.GetComponent <Entity>().affinity = player.GetComponent <Entity>().affinity;
        float bulletMagnitude = .5f;

        bullet.yVector            = bulletMagnitude;
        bullet.transform.position = origin;
        bullet.GetComponent <Rigidbody2D>().velocity = player.GetComponent <Rigidbody2D>().velocity;
        Physics2D.IgnoreCollision(bullet.GetComponent <Collider2D>(), player.GetComponent <Collider2D>());
        RegisterBullet();
    }
Exemplo n.º 9
0
    public void Fire(GameObject target)
    {
        if (timeSinceLastFire >= fireDelay)
        {
            timeSinceLastFire = 0f;
            GameObject       bulletPrefab = Resources.Load("Bullet") as GameObject;
            GameObject       bulletObject = Instantiate(bulletPrefab, transform.position, Quaternion.identity) as GameObject;
            BulletProjectile bullet       = bulletObject.GetComponent <BulletProjectile>();
            bullet.speed = 8f;
            bullet.owner = gameObject;

            Vector3 direction = target.transform.position - transform.position;
            direction.Normalize();
            bullet.xVector = direction.x + core.Velocity().x;
            bullet.yVector = direction.y;
        }
    }
Exemplo n.º 10
0
        public BulletWeapon(World world, WeaponType type, Target target, Actor origin, uint id) : base(world, type, target, origin, id)
        {
            projectile = (BulletProjectile)type.Projectile;

            Angle = (Position - TargetPosition).FlatAngle;

            TargetPosition += getInaccuracy(projectile.Inaccuracy);

            calculateStartSpeed();

            if (projectile.OrientateToTarget)
            {
                Rotation = new VAngle(0, 0, Angle);
            }

            rayPhysics = new RayPhysics(world);
        }
Exemplo n.º 11
0
    private void OnTriggerEnter(Collider other)
    {
        Debug.Log("hit");
        SimpleProjectile sp = other.gameObject.GetComponent <SimpleProjectile>();
        BulletProjectile bp = other.gameObject.GetComponent <BulletProjectile>();

        if (used == false)
        {
            if (sp || bp)
            {
                Debug.Log("BUTTON HIT!");

                newobj = Instantiate(spawnPrefab, spawnLocation.transform.position,
                                     spawnLocation.transform.rotation);
            }
            used = true;
        }
    }
Exemplo n.º 12
0
        public BulletWeapon(World world, WeaponInit init) : base(world, init)
        {
            projectile = (BulletProjectile)Type.Projectile;

            speed     = init.Convert("Speed", Vector.Zero);
            speedLeft = init.Convert("SpeedLeft", Vector.Zero);
            if (speed == Vector.Zero)
            {
                calculateStartSpeed();
            }

            if (projectile.OrientateToTarget)
            {
                Rotation = new VAngle(0, 0, Angle);
            }

            rayPhysics = new RayPhysics(world);
        }
Exemplo n.º 13
0
    void FireProjectile()
    {
        Vector3 fireLocation;

        if (player.transform.position.x < transform.position.x)
        {
            fireLocation = fireLeft.transform.position;
            GameObject projectile = Instantiate(bullet, fireLocation, quaternion.identity);
            projectileScript             = projectile.GetComponent <BulletProjectile>();
            projectileScript.movingRight = false;
        }
        else
        {
            fireLocation = fireRight.transform.position;
            GameObject projectile = Instantiate(bullet, fireLocation, quaternion.identity);
            projectileScript             = projectile.GetComponent <BulletProjectile>();
            projectileScript.movingRight = true;
        }
    }
Exemplo n.º 14
0
    void CreateBullet(Vector2 firePoint)
    {
        BulletProjectile bulletProjectile = Instantiate(bullet, firePoint, transform.rotation).GetComponent <BulletProjectile>();

        bulletProjectile.UpdateVariables(speed, damage, range);
    }
Exemplo n.º 15
0
 /// <summary>
 /// Called when the given <see cref="BulletProjectile"/> is destroyed in any way
 /// </summary>
 /// <param name="bullet"></param>
 public virtual void OnBulletProjectileDestroyed(BulletProjectile bullet, bool isMortarShrapnel, bool isFlameBreath, bool isRepairFire)
 {
 }
Exemplo n.º 16
0
 /// <summary>
 /// Called when a <see cref="BulletProjectile"/> starts moving
 /// </summary>
 /// <param name="bullet"></param>
 public virtual void OnBulletProjectileStartedMoving(BulletProjectile bullet, bool isMortarShrapnel, bool isFlameBreath, bool isRepairFire)
 {
 }