void ShootFireball() { if (controller.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)) { //Get a fireball from the object pool. GameObject fireball = GetFireBall(); fireball.GetComponent <PhotonView>().TransferOwnership(PhotonNetwork.player.ID); //Changes ownership when spawned fireball.transform.localScale = visual_Fireball.transform.localScale; fireball.transform.position = fireball_Emitter.transform.position; fireball.GetComponent <Rigidbody>().velocity = Vector3.zero; //Kyle - Added PhotonNetwork so object can be tracked by the network //Temporary_Fireball_Handler = Instantiate(fireball, fireball_Emitter.transform.position, fireball_Emitter.transform.rotation) as GameObject; //Sometimes bullets may appear rotated incorrectly due to the way its pivot was set from the original modeling package. //This is EASILY corrected here, you might have to rotate it from a different axis and or angle based on your particular mesh. fireball.transform.Rotate(Vector3.left * 90); //Retrieve the Rigidbody component from the instantiated Bullet and control it. Rigidbody Temporary_RigidBody; Temporary_RigidBody = fireball.GetComponent <Rigidbody>(); //Tell the bullet to be "pushed" forward by an amount set by Bullet_Forward_Force. Temporary_RigidBody.AddForce(-(transform.up * 1000)); //Make fireball invisible StartCoroutine(DestroyFireball(3.0f)); //set to false for timer ReadyToFire = false; timer = 4.0f; //Make fireball original size again visual_Fireball.transform.localScale = fireballStartSize; } }
void Update() { int speed = 10000; var q = Quaternion.LookRotation(target.position - transform.position); transform.rotation = Quaternion.RotateTowards(transform.rotation, q, speed * Time.deltaTime); if (shotActive == true && GameObject.Find("Player").GetComponent <TrackPlayerLocation>().player.transform.position.x > transform.position.x - 700 && GameObject.Find("Player").GetComponent <TrackPlayerLocation>().player.transform.position.x < target.position.x + 7000 && GameObject.Find("Player").GetComponent <TrackPlayerLocation>().player.transform.position.z > target.position.z - 700 && GameObject.Find("Player").GetComponent <TrackPlayerLocation>().player.transform.position.z < target.position.z + 700) { GameObject Temporary_Bullet_Handler; Temporary_Bullet_Handler = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject; Temporary_Bullet_Handler.transform.Rotate(Vector3.right * 90); Rigidbody Temporary_RigidBody; Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>(); Temporary_RigidBody.AddForce(transform.forward * Bullet_Forward_Force); Destroy(Temporary_Bullet_Handler, 4); shotActive = false; } if (shotActive == false) { if (shootCount < 40) { shootCount++; } else { shotActive = true; shootCount = 0; } } }
void Fire() { GameObject Temporary_Bullet_Handler; Temporary_Bullet_Handler = Instantiate(Bullet, Barrel.transform.position, Barrel.transform.rotation) as GameObject; //Sometimes bullets may appear rotated incorrectly due to the way its pivot was set from the original modeling package. //This is EASILY corrected here, you might have to rotate it from a different axis and or angle based on your particular mesh. //don't change this or the bullets will fly up/to the side Temporary_Bullet_Handler.transform.Rotate(Vector3.left * 0); //Retrieve the Rigidbody component from the instantiated Bullet and control it. Rigidbody Temporary_RigidBody; Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>(); //Tell the bullet to be "pushed" forward by an amount set by Bullet_Forward_Force. Temporary_RigidBody.AddForce(transform.forward * Bullet_Forward_Force); //don't correct this //Temporary_RigidBody.AddForce(transform.up * Bullet_Forward_Force); //Basic Clean Up, set the Bullets to self destruct after 10 Seconds, I am being VERY generous here, normally 3 seconds is plenty. Destroy(Temporary_Bullet_Handler, 2.0f); // yield WaitForSeconds(5); }
void SageShoot() { if (Input.GetMouseButton(1)) { ChargeUps(); if (Input.GetMouseButtonDown(0)) { GameObject Temporary_Projectile_Handler; Temporary_Projectile_Handler = Instantiate(Projectile, Projectile_Emitter.transform.position, Projectile_Emitter.transform.rotation) as GameObject; Temporary_Projectile_Handler.transform.Rotate(Vector3.forward * 90); Temporary_Projectile_Handler.transform.localScale += new Vector3(sage_Current_Projectile_Size / 1.5f, sage_Current_Projectile_Size / 1.5f, sage_Current_Projectile_Size / 1.5f); Rigidbody Temporary_RigidBody; Temporary_RigidBody = Temporary_Projectile_Handler.GetComponent <Rigidbody>(); Temporary_RigidBody.AddForce(transform.right * sage_Projectile_Forward_Force); Debug.Log(Temporary_Projectile_Handler.transform.localScale); rangedChargeScript.Reset(); sage_Current_Projectile_Size = 0f; Destroy(Temporary_Projectile_Handler, 5f); } } else { sage_Current_Projectile_Size = 0f; rangedChargeScript.Reset(); } }
void Shoot() { RaycastHit hit; if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range)) { Debug.Log(hit.transform.name); Target target = hit.transform.GetComponent <Target>(); if (target != null) { target.takeDamage(damage); } if (hit.rigidbody != null) { hit.rigidbody.AddForce(-hit.normal * impactForce); } GameObject Temporary_Bullet_Handler; Temporary_Bullet_Handler = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject; Rigidbody Temporary_RigidBody; Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>(); Temporary_RigidBody.AddForce(transform.forward * Bullet_Forward_Force); Destroy(Temporary_Bullet_Handler, 5.0f); } }
void Update() { if (Input.GetKeyDown(KeyCode.Mouse0)) { Shoot(); GameObject Temporary_Bullet_Handler; Temporary_Bullet_Handler = Instantiate(Bullet, BulletEmitter.transform.position, BulletEmitter.transform.rotation) as GameObject; //Temporary_Bullet_Handler.transform.Rotate(Vector3.left * 90); Rigidbody Temporary_RigidBody; Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody> (); Temporary_RigidBody.AddForce(transform.forward * Bullet_Forward_Force); Destroy(Temporary_Bullet_Handler, 0.8f); } if (Input.GetKeyDown(KeyCode.Mouse0)) { AudioSource audio = GetComponent <AudioSource> (); audio.Play(); } }
void WarriorShoot() { if (Input.GetMouseButton(1)) { ChargeUps(); if (Input.GetMouseButtonDown(0)) { GameObject Temporary_Projectile_Handler; Temporary_Projectile_Handler = Instantiate(Projectile, Projectile_Emitter.transform.position, Projectile_Emitter.transform.rotation) as GameObject; Temporary_Projectile_Handler.transform.Rotate(Vector3.forward * 90); // Projectile spin feel Rigidbody Temporary_RigidBody; Temporary_RigidBody = Temporary_Projectile_Handler.GetComponent <Rigidbody>(); Temporary_RigidBody.AddForce(transform.right * warrior_Projectile_Forward_Force); forceMultiplier = 1f; charge = 0f; rangedChargeScript.Reset(); Destroy(Temporary_Projectile_Handler, 5f); } } else { forceMultiplier = 1f; rangedChargeScript.Reset(); } }
// Update is called once per frame void Update() { delayTime = (Random.Range(delayMin, delayMax)); if (canShoot == true) { //The Bullet Instantiation happens here. GameObject Temporary_Bullet_handler; Temporary_Bullet_handler = Instantiate(projectile, gameObject.transform.position, gameObject.transform.rotation) as GameObject; //Sometimes bullets may appear rotated incorrectly due to the way its pivot was set from the original modeling package. //This is EASILY corrected here, you might have to rotate it from a different axis and/or angle based on your particular mesh. Temporary_Bullet_handler.transform.Rotate(Vector3.left); //Retrieve the Rigidbody component from the instantiated Bullet and control it. Rigidbody Temporary_RigidBody; Temporary_RigidBody = Temporary_Bullet_handler.GetComponent <Rigidbody>(); //Tell the bullet to be "pushed" forward by an amount set by Bullet_Forward_Force. Temporary_RigidBody.AddForce(transform.forward * projectileForce, ForceMode.Impulse); //Basic Clean Up, set the Bullets to self destruct after 10 Seconds, I am being VERY generous here, normally 3 seconds is plenty. Destroy(Temporary_Bullet_handler, projectileLifetime); canShoot = false; StartCoroutine(ShootDelay()); } }
// Update is called once per frame void Update() { if (Input.GetKey(KeyCode.Space) && isFireCount < 5) { isFiring = true; //The Bullet instantiation happens here. GameObject Temporary_Bullet_Handler; Temporary_Bullet_Handler = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject; Temporary_Bullet_Handler.transform.Rotate(Vector3.left * 90); //Retrieve the Rigidbody component from the instantiated Bullet and control it. Rigidbody Temporary_RigidBody; Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>(); //Tell the bullet to be "pushed" forward by an amount set by Bullet_Forward_Force. Temporary_RigidBody.AddForce(transform.forward * Bullet_Forward_Force); //Basic Clean Up, set the Bullets to self destruct after 4 Second. Destroy(Temporary_Bullet_Handler, 4); } else if (isFireCount > 20) { isFiring = false; isFireCount = 0; } else { isFiring = false; } isFireCount++; }
public void PowerMove() { if (Phant) { int RandomPos = Random.Range(1, Position.Length); Instantiate(GhostDummy, Position[RandomPos].transform.position, Quaternion.identity); Instantiate(TeleportParticle, transform.position, Quaternion.identity); } else { Rigidbody Temporary_RigidBody; GameObject newBullet; audioSrc.PlayOneShot(powerShoot); if (Fire) { Projectile = FireBall; } else if (Dummy) { Projectile = PhantBall; } else if (Ice) { Projectile = IceBall; } newBullet = Instantiate(Projectile, EmitterCenter.transform.position, Emitter.transform.rotation); newBullet.transform.Rotate(0, 90, 0); newBullet.transform.LookAt(Camera.main.transform.position); Temporary_RigidBody = newBullet.GetComponent <Rigidbody>(); Temporary_RigidBody.AddForce(newBullet.transform.forward * projectileForce * 2); Destroy(newBullet, 30.0f); } }
public void Shoot() { Rigidbody Temporary_RigidBody; GameObject newBullet; audioSrc.PlayOneShot(shoot); if (Fire) { Projectile = FireCrystal; } if (Phant || Dummy) { Projectile = PhantCrystal; } if (Ice) { Projectile = IceCrystal; } newBullet = Instantiate(Projectile, Emitter.transform.position, Emitter.transform.rotation); newBullet.transform.Rotate(0, 90, 0); newBullet.transform.LookAt(Camera.main.transform.position); Temporary_RigidBody = newBullet.GetComponent <Rigidbody>(); Temporary_RigidBody.AddForce(newBullet.transform.forward * projectileForce); Destroy(newBullet, 30.0f); }
public IEnumerator FragmentSpawn() { transform.Rotate(rotX = Random.Range(0, 360), rotY = Random.Range(0, 360), rotZ = Random.Range(0, 360)); GameObject tempAsteroid; tempAsteroid = Instantiate(asteroidFragments[Random.Range(0, asteroidFragments.Count)], gameObject.transform.position, gameObject.transform.rotation) as GameObject; //Sometimes bullets may appear rotated incorrectly due to the way its pivot was set from the original modeling package. //This is EASILY corrected here, you might have to rotate it from a different axis and/or angle based on your particular mesh. tempAsteroid.transform.Rotate(Vector3.left); tempAsteroid.transform.GetChild(0).GetComponent <AsteroidScript>().rotX = Random.Range(0, 360); tempAsteroid.transform.GetChild(0).GetComponent <AsteroidScript>().rotY = Random.Range(0, 360); tempAsteroid.transform.GetChild(0).GetComponent <AsteroidScript>().rotZ = Random.Range(0, 360); tempAsteroid.transform.GetChild(0).GetComponent <AsteroidScript>().moveX = Random.Range(40, 100); tempAsteroid.transform.GetChild(0).GetComponent <AsteroidScript>().moveY = Random.Range(40, 100); tempAsteroid.transform.GetChild(0).GetComponent <AsteroidScript>().moveZ = Random.Range(40, 100); //Retrieve the Rigidbody component from the instantiated Bullet and control it. Rigidbody Temporary_RigidBody; Temporary_RigidBody = tempAsteroid.GetComponent <Rigidbody>(); //Tell the bullet to be "pushed" forward by an amount set by Bullet_Forward_Force. Temporary_RigidBody.AddForce(transform.forward * Random.Range(2000, 5000), ForceMode.Impulse); fragmentAmount -= 1; if (fragmentAmount > 0) { StartCoroutine(FragmentSpawn()); } yield return(new WaitForSeconds(0)); }
// Update is called once per frame void Update() { if (Input.GetKeyDown("s")) { //The Bullet instantiation happens here. GameObject Temporary_Bullet_Handler; Temporary_Bullet_Handler = Instantiate(Bullet, BulletEmitter.transform.position, BulletEmitter.transform.rotation) as GameObject; //Sometimes bullets may appear rotated incorrectly due to the way its pivot was set from the original modeling package. //This is EASILY corrected here, you might have to rotate it from a different axis and or angle based on your particular mesh. //Temporary_Bullet_Handler.transform.Rotate(Vector3.left * 90); //Retrieve the Rigidbody component from the instantiated Bullet and control it. Rigidbody Temporary_RigidBody; Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>(); //Tell the bullet to be "pushed" forward by an amount set by Bullet_Forward_Force. Temporary_RigidBody.AddForce(transform.forward * Bullet_Forward_Force); //Basic Clean Up, set the Bullets to self destruct after 10 Seconds, I am being VERY generous here, normally 3 seconds is plenty. Destroy(Temporary_Bullet_Handler, 10.0f); RaycastHit hit; Ray ray = new Ray(transform.position, transform.forward); if (Physics.Raycast(ray, out hit, 200f)) { hit.transform.GetComponent <EnemyHealth>().RemoveHealth(enemyDamage); } else if (Physics.Raycast(ray, out hit, 300f)) { hit.transform.GetComponent <BoarHealth>().RemoveHealth(enemyDamage); } } }
void spawn() { //int randomHurdle = UnityEngine.Random.Range(0, hurdles.Length-1); GameObject Temporary_Bullet_Handler; int randomHurdle = Random.Range(0, 11); float xpos = Random.Range(-1.2f, 1.2f); float zpos = Random.Range(15f, 20f); float ypos = 2.88f; int abol = Random.Range(1, 10); int tabol = Random.Range(1, 10); if (abol * tabol < 10) { //1 Vector3 hposition = new Vector3(xpos, ypos, player.position.z + zpos); Temporary_Bullet_Handler = Instantiate(hurdles[0], hposition, hurdles[0].transform.rotation); //2 hposition = new Vector3(xpos + 1f, ypos, player.position.z + zpos); Temporary_Bullet_Handler = Instantiate(hurdles[1], hposition, hurdles[1].transform.rotation); //3 hposition = new Vector3(xpos + 1, ypos - 1f, player.position.z + zpos); Temporary_Bullet_Handler = Instantiate(hurdles[2], hposition, hurdles[2].transform.rotation); //4 hposition = new Vector3(xpos - 1, ypos - 1f, player.position.z + zpos); Temporary_Bullet_Handler = Instantiate(hurdles[3], hposition, hurdles[3].transform.rotation); Rigidbody Temporary_RigidBody; Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>(); Temporary_RigidBody.AddForce(transform.forward * Bullet_Forward_Force); } StartCoroutine(spawnHurdle()); }
void Shoot() { if (Time.time > nextFire) { shoot.Play(); nextFire = Time.time + fireRate; //The Bullet instantiation happens here. GameObject Temporary_Bullet_Handler; Temporary_Bullet_Handler = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject; //Sometimes bullets may appear rotated incorrectly due to the way its pivot was set from the original modeling package. //This is EASILY corrected here, you might have to rotate it from a different axis and or angle based on your particular mesh. Temporary_Bullet_Handler.transform.Rotate(Vector3.left * 90); //Retrieve the Rigidbody component from the instantiated Bullet and control it. Rigidbody Temporary_RigidBody; Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>(); //Tell the bullet to be "pushed" forward by an amount set by Bullet_Forward_Force. Temporary_RigidBody.AddForce(transform.forward * Bullet_Forward_Force); //Basic Clean Up, set the Bullets to self destruct after 10 Seconds, I am being VERY generous here, normally 3 seconds is plenty. Destroy(Temporary_Bullet_Handler, 2.0f); } }
void Range() { GameObject Temporary_Bullet_Handler = null; if (Input.GetButtonUp("X360_B") && XboxPlayerControlScript.isRoll == false && !TextManagerScript.conversationStarted && RangeChargeDuration < TimeTakenToStartCharge && !isAttack && !spinAttack) { anim.SetBool("Aim", false); anim.SetBool("Shoot", true); if (RangeAttRate <= 0.0f) { isRange = false; Temporary_Bullet_Handler = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject; Rigidbody Temporary_RigidBody; Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody> (); Temporary_RigidBody.AddForce(transform.forward * Bullet_Forward_Force); RangeAttRate = characterstats.RangeAttRate; RangeChargeDuration = 0.0f; } Destroy(Temporary_Bullet_Handler, 3.0f); } if (Input.GetButtonUp("X360_B") && RangeChargeDuration > TimeTakenToStartCharge && XboxPlayerControlScript.isRoll == false && !isAttack && !spinAttack) { isRange = false; anim.SetBool("Aim", false); anim.SetBool("Shoot", true); ChargeRangeAttack(RangeChargeDuration); RangeChargeDuration = 0.0f; ChargeBarUI.GetComponent <ChargeBarScript> ().chargeDuration = RangeChargeDuration; anim.SetBool("Run", false); } }
public void shoot() { Rigidbody Temporary_RigidBody; GameObject newBullet; if (shootLeft) { anim.SetTrigger("ThrowLeft"); audioSrc.PlayOneShot(bossThrow); shootLeft = false; shootRight = true; Projectile = IceSpikeProjectile; newBullet = Instantiate(Projectile, IceSpikeEmitterLeft.transform.position, IceSpikeEmitterLeft.transform.rotation); newBullet.transform.LookAt(Camera.main.transform.position); Temporary_RigidBody = newBullet.GetComponent <Rigidbody>(); Temporary_RigidBody.AddForce(newBullet.transform.forward * projectileForce); Destroy(newBullet, 30.0f); } else if (shootRight) { anim.SetTrigger("ThrowRight"); audioSrc.PlayOneShot(bossThrow); shootRight = false; shootLeft = true; Projectile = IceSpikeProjectile; newBullet = Instantiate(Projectile, IceSpikeEmitterRight.transform.position, IceSpikeEmitterRight.transform.rotation); newBullet.transform.LookAt(Camera.main.transform.position); Temporary_RigidBody = newBullet.GetComponent <Rigidbody>(); Temporary_RigidBody.AddForce(newBullet.transform.forward * projectileForce); Destroy(newBullet, 10.0f); } }
public void ammu() { GameObject Temporary_Bullet_Handler; Temporary_Bullet_Handler = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject; //korjaa jos ammus hatullaa Temporary_Bullet_Handler.transform.Rotate(Vector3.left * 90); //työnnä ammusta Rigidbody Temporary_RigidBody; Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody> (); Temporary_RigidBody.AddForce(transform.forward * speed); //tuhoa ammus Destroy(Temporary_Bullet_Handler, 2.0f); timeBtwShots = startTimeBtwShots; //suuliekki GameObject Temporary_Flare_Handler; Temporary_Flare_Handler = Instantiate(Flare, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject; Destroy(Temporary_Flare_Handler, 0.2f); Ammo--; }
public void ShootCharged() { if (flameState) { projectile = chargeFireBallPrefab; audioSrc.PlayOneShot(norFireShot); } else if (phantState) { projectile = chargeThunderBallPrefab; audioSrc.PlayOneShot(norThunderShot); } else if (frostState) { projectile = chargeIceBallPrefab; audioSrc.PlayOneShot(norIceShot); } Rigidbody Temporary_RigidBody; GameObject newBullet; newBullet = Instantiate(projectile, chargedEmitter.transform.position, chargedEmitter.transform.rotation); newBullet.transform.Rotate(0, 90, 0); newBullet.transform.LookAt(Camera.main.transform.position); Temporary_RigidBody = newBullet.GetComponent <Rigidbody>(); Temporary_RigidBody.AddForce(newBullet.transform.forward * projectileForce * 2); Destroy(newBullet, 30.0f); }
void Update() { // if (Input.GetKeyDown("space")) if (/* isDragged && */ Time.time > nextFireBullet) { nextFireBullet = Time.time + FireRate; //The Bullet instantiation happens here. // "Kugel" schould be "EnemyBullet" GameObject Temporary_Bullet_Handler; Temporary_Bullet_Handler = Instantiate(Kugel, EnemyBulletSpawner.transform.position, EnemyBulletSpawner.transform.rotation) as GameObject; //Sometimes bullets may appear rotated incorrectly due to the way its pivot was set from the original modeling package. //This is EASILY corrected here, you might have to rotate it from a different axis and or angle based on your particular mesh. Temporary_Bullet_Handler.transform.Rotate(Vector3.left * 90); //Retrieve the Rigidbody component from the instantiated Bullet and control it. Rigidbody Temporary_RigidBody; Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>(); //Tell the bullet to be "pushed" forward by an amount set by Bullet_Forward_Force. Temporary_RigidBody.AddForce(transform.forward * Bullet_Forward_Force); //Basic Clean Up, set the Bullets to self destruct after 10 Seconds // needs to get destroyed when hiting Destroy(Temporary_Bullet_Handler, 5.0f); } }
// Update is called once per frame void FixedUpdate() { float moveHorizontal = Input.GetAxis("Horizontal"); float moveVertical = Input.GetAxis("Vertical"); Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical); rb.AddForce(movement * speed); // joint.connectedBody = Esfera2.rigidbody; if (Input.GetKeyDown("space")) { // Bullet instantiation GameObject Temporary_Bullet_Handler; Temporary_Bullet_Handler = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject; // what, from where y rotation //por si el pivot se seteo mal de esta manera lo corregimos Temporary_Bullet_Handler.transform.Rotate(Vector3.left * 90); Rigidbody Temporary_RigidBody; Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>(); //tell bullet to be pushed Temporary_RigidBody.AddForce(transform.forward * Bullet_Forward_Force); Destroy(Temporary_Bullet_Handler, 10.0f); } }
public void Fire() { if (pCurrentAmmo > 0) { //The Bullet instantiation happens here. GameObject Temporary_Bullet_Handler; Temporary_Bullet_Handler = Instantiate(pBullet, pBarrel.transform.position, pBarrel.transform.rotation) as GameObject; //Sometimes bullets may appear rotated incorrectly due to the way its pivot was set from the original modeling package. Temporary_Bullet_Handler.transform.Rotate(Vector3.left * 90); //Retrieve the Rigidbody component from the instantiated Bullet and control it. Rigidbody Temporary_RigidBody; Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>(); //Tell the bullet to be "pushed" forward by an amount set by Bullet_Forward_Force. Temporary_RigidBody.AddForce(transform.forward * pSpeed); //Subtract bullets from magazine. pCurrentAmmo--; pAmmo.text = pCurrentAmmo.ToString(); //Basic Clean Up, set the Bullets to self destruct after 10 Seconds, I am being VERY generous here, normally 3 seconds is plenty. Destroy(Temporary_Bullet_Handler, 10.0f); } else { Debug.Log("No bullets left!"); } }
public override void Fire() { AudioSource Audio = GetComponent <AudioSource>(); Audio.PlayOneShot(ShotSound); //The Bullet instantiation happens here. GameObject Temporary_Bullet_Handler; Temporary_Bullet_Handler = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject; //Sometimes bullets may appear rotated incorrectly due to the way its pivot was set from the original modeling package. //This is EASILY corrected here, you might have to rotate it from a different axis and or angle based on your particular mesh. Temporary_Bullet_Handler.transform.Rotate(Vector3.left * 180); //Retrieve the Rigidbody component from the instantiated Bullet and control it. Rigidbody2D Temporary_RigidBody; Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody2D>(); //Tell the bullet to be "pushed" forward by an amount set by Bullet_Forward_Force. Temporary_RigidBody.AddForce((transform.right * transform.localScale.x) * Bullet_Forward_Force); //Temporary_RigidBody.AddForce(transform.right * Bullet_Forward_Force); //Basic Clean Up, set the Bullets to self destruct after 10 Seconds, I am being VERY generous here, normally 3 seconds is plenty. Destroy(Temporary_Bullet_Handler, 3.0f); }
// Update is called once per frame void Update() { if (shoot == true && timer <= 0) { timer = fireRate; //The Bullet instantiation happens here. GameObject Temporary_Bullet_Handler; Temporary_Bullet_Handler = Instantiate(Bullet, spawnPoint.transform.position, this.transform.rotation) as GameObject; GetComponent <AudioSource>().PlayOneShot(gunShot); //Sometimes bullets may appear rotated incorrectly due to the way its pivot was set from the original modeling package. //This is EASILY corrected here, you might have to rotate it from a different axis and or angle based on your particular mesh. Temporary_Bullet_Handler.transform.Rotate(Vector3.left * 90); //Retrieve the Rigidbody component from the instantiated Bullet and control it. Rigidbody Temporary_RigidBody; Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>(); //Tell the bullet to be "pushed" forward by an amount set by Bullet_Forward_Force. Temporary_RigidBody.AddForce(transform.right * speed * Time.deltaTime); } else if (shoot == true) { timer -= 1 * Time.deltaTime; } else if (timer != 1) { timer = 1; } }
void GunShoot() { CurrentAmmo = CurrentAmmo - 1; CurrentAmmoText.text = CurrentAmmo.ToString(); //Ump.AddForce(-1, 1, AddedRecoil, ForceMode.Impulse); muzzleflash.Play(); int ShotNo = Random.Range((int)1, (int)4); if (ShotNo == 1) { PlayShot1(); } if (ShotNo == 2) { PlayShot2(); } if (ShotNo == 3) { PlayShot3(); } GameObject Temporary_Bullet_Handler; Temporary_Bullet_Handler = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject; Temporary_Bullet_Handler.transform.Rotate(Vector3.right * 90); Rigidbody Temporary_RigidBody; Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>(); Temporary_RigidBody.AddForce(transform.forward * Bullet_Forward_Force); Destroy(Temporary_Bullet_Handler, 10.0f); }
private void HandAttachedUpdate(Hand hand) { transform.localRotation = Quaternion.Euler(-90.0f, 0f, -90.0f); if (Input.GetMouseButtonDown(0) || hand.grabPinchAction.GetStateDown(hand.handType)) { //The Bullet instantiation happens here. GameObject Temporary_Bullet_Handler; Temporary_Bullet_Handler = Instantiate(bullet, bulletEmiter.position, bulletEmiter.rotation) as GameObject; //Sometimes bullets may appear rotated incorrectly due to the way its pivot was set from the original modeling package. //This is EASILY corrected here, you might have to rotate it from a different axis and or angle based on your particular mesh. Temporary_Bullet_Handler.transform.Rotate(Vector3.left * 90); //Retrieve the Rigidbody component from the instantiated Bullet and control it. Rigidbody Temporary_RigidBody; Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>(); //Tell the bullet to be "pushed" forward by an amount set by Bullet_Forward_Force. Temporary_RigidBody.AddForce(bulletEmiter.right * bulletForce); //play sound sound.volume = volumeShot; sound.Play(); //Basic Clean Up, set the Bullets to self destruct after 10 Seconds, I am being VERY generous here, normally 3 seconds is plenty. IEnumerator coroutine; coroutine = DestroyBullet(Temporary_Bullet_Handler); StartCoroutine(coroutine); } }
void Update() { time += Time.deltaTime; if (time >= interpolationPeriod) { time = 0.0f; // execute block of code here //The Bullet instantiation happens here. GameObject Temporary_Bullet_Handler; Temporary_Bullet_Handler = Instantiate(Bullet, Bullet_Emitter.transform.position + new Vector3(0.0f, 0.0f, 0.0f), Bullet_Emitter.transform.rotation) as GameObject; Temporary_Bullet_Handler.transform.Rotate(Vector3.forward * 100); Temporary_Bullet_Handler.transform.Rotate(Vector3.right * 90); Temporary_Bullet_Handler.transform.Rotate(Vector3.up * -10); Rigidbody Temporary_RigidBody; Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>(); Temporary_RigidBody.AddForce(transform.up * Bullet_Up_Force); Destroy(Temporary_Bullet_Handler, 5.0f); } }
void Update() { if (Input.GetKey(KeyCode.Mouse0) && Time.time > nextFire && ammoManager.CanFire()) { nextFire = Time.time + fireRate; FireParticles(); //The Bullet instantiation happens here. GameObject Temporary_Bullet_Handler; Temporary_Bullet_Handler = Instantiate(bullet, bulletEmitter.transform.position, bulletEmitter.transform.rotation) as GameObject; //Sometimes bullets may appear rotated incorrectly due to the way its pivot was set from the original modeling package. //This is EASILY corrected here, you might have to rotate it from a different axis and or angle based on your particular mesh. //Temporary_Bullet_Handler.transform.Rotate(Vector3.left * 90); //Retrieve the Rigidbody component from the instantiated Bullet and control it. Rigidbody Temporary_RigidBody; Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>(); //Tell the bullet to be "pushed" forward by an amount set by Bullet_Forward_Force. Temporary_RigidBody.AddForce(transform.forward * bulletForwardForce); //Lower the ammo capacity ammoManager.Fire(); //ammoImage.fillAmount -= 0.2f / ammo; Temporary_Bullet_Handler.GetComponent <BulletDamage>().Attacker("Player"); //Basic Clean Up, set the Bullets to self destruct after 3 Seconds. Destroy(Temporary_Bullet_Handler, 6.0f); } }
// Update is called once per frame void Update() { //1. Fly up and down if (Time.time > startTime + travelTime) { //reverse travel direction ReverseDirection(); } float currentTime = (Time.time - startTime) / travelTime; transform.position = Vector3.Lerp(originalPosition, destination, currentTime); if (Time.frameCount == frameCount) { frameCount += 40; //The Bullet instantiation happens here. GameObject Temporary_Bullet_Handler; Temporary_Bullet_Handler = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject; //Sometimes bullets may appear rotated incorrectly due to the way its pivot was set from the original modeling package. //This is EASILY corrected here, you might have to rotate it from a different axis and or angle based on your particular mesh. Temporary_Bullet_Handler.transform.Rotate(Vector3.left * 90); //Retrieve the Rigidbody component from the instantiated Bullet and control it. Rigidbody Temporary_RigidBody; Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>(); //Tell the bullet to be "pushed" forward by an amount set by Bullet_Forward_Force. Temporary_RigidBody.AddForce(transform.right * Bullet_Forward_Force); //Basic Clean Up, set the Bullets to self destruct after 10 Seconds, I am being VERY generous here, normally 3 seconds is plenty. Destroy(Temporary_Bullet_Handler, 10.0f); } }
void Update() { if (activated) { /* Firing Logic */ lullCounter++; if (lullCounter > LullPeriod) { lullCounter = 0; isFiring = !isFiring; } if (isFiring) { firingCounter++; if (firingCounter > FiringPeriod) { source.clip = bulletAudio; source.Play(); firingCounter = 0; //The Bullet instantiation happens here. GameObject Temporary_Bullet_Handler; Temporary_Bullet_Handler = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject; //Retrieve the Rigidbody component from the instantiated Bullet and control it. Rigidbody2D Temporary_RigidBody; Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody2D>(); //Tell the bullet to be "pushed" forward by an amount set by Bullet_Forward_Force. Temporary_RigidBody.AddForce(Vector2.left * Bullet_Forward_Force); //Basic Clean Up, set the Bullets to self destruct after 10 Seconds, I am being VERY generous here, normally 3 seconds is plenty. Destroy(Temporary_Bullet_Handler, 5.0f); } /* Bob Logic */ bobCounter++; if (bobCounter > BobPeriod) { /* Reset */ bobCounter = 0; if (bobUp) { bobState++; parentScalar.localScale += new Vector3(0f, 0.025f, 0f); } else { bobState--; parentScalar.localScale -= new Vector3(0f, 0.025f, 0f); } if (bobState == 3 || bobState == 0) { bobUp = !bobUp; } } } } }