private BulletProjectile newProjectile() { GameObject bulletObject = Instantiate(bulletPrefab, transform.position, Quaternion.identity) as GameObject; BulletProjectile bullet = bulletObject.GetComponent <BulletProjectile>(); return(bullet); }
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); }
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; }
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; }
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); }
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); } }
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(); }
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; } }
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); }
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; } }
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); }
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; } }
void CreateBullet(Vector2 firePoint) { BulletProjectile bulletProjectile = Instantiate(bullet, firePoint, transform.rotation).GetComponent <BulletProjectile>(); bulletProjectile.UpdateVariables(speed, damage, range); }
/// <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) { }
/// <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) { }