public void Shoot() { GameObject Temporary_Bullet_Handler; Temporary_Bullet_Handler = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject; Temporary_Bullet_Handler.tag = "Bullet"; Rigidbody2D Temporary_RigidBody; Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody2D>(); Temporary_RigidBody.AddForce(transform.forward + transform.TransformVector(0, 300, 0)); Destroy(Temporary_Bullet_Handler, 7.0f); }
void shootWithIntervals() { 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); Rigidbody Temporary_RigidBody; Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>(); Temporary_RigidBody.AddForce(transform.forward * Bullet_Forward_Force); Destroy(Temporary_Bullet_Handler, 0.1f); }
void Update() { distFromStart = transform.position.x - _originalPosition.x; if (isGoingLeft) { // If gone too far, switch direction if (distFromStart < -distance) { SwitchDirection(); } _transform.Translate(-velocity.x * Time.deltaTime, 0, 0); } else { // If gone too far, switch direction if (distFromStart > distance) { SwitchDirection(); } _transform.Translate(velocity.x * Time.deltaTime, 0, 0); } // Firing logic firingCounter++; if (firingCounter > firingPeriod) { bulletAudioSource.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; Physics2D.IgnoreCollision(Temporary_Bullet_Handler.GetComponent <Collider2D>(), GetComponent <Collider2D>()); //Retrieve the Rigidbody component from the instantiated Bullet and control it. Rigidbody2D Temporary_RigidBody; Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody2D>(); Vector3 playerPos = GameObject.Find("Player").transform.position; Vector3 bulletVec = playerPos - transform.position; bulletVec.Normalize(); //Tell the bullet to be "pushed" forward by an amount set by Bullet_Forward_Force. Temporary_RigidBody.AddForce(bulletVec * 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 Shoot() { GameObject Temporary_Bullet_Handler; Temporary_Bullet_Handler = Instantiate(bulletPrefab, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject; Temporary_Bullet_Handler.name = Temporary_Bullet_Handler.name.Substring(0, Temporary_Bullet_Handler.name.Length - 7); Temporary_Bullet_Handler.transform.Rotate(Vector3.right * 90); Rigidbody Temporary_RigidBody; Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>(); Temporary_RigidBody.AddForce(transform.forward * bulletSpeed * bulletWay); Destroy(Temporary_Bullet_Handler, 0.8f); }
// Update is called once per frame void Update() { float distance = Vector3.Distance(target.position, transform.position); if (distance <= lookRadius) { agent.SetDestination(target.position); anim.SetBool("running", true); if (distance <= agent.stoppingDistance) { anim.SetBool("running", false); } } if (distance > lookRadius) { anim.SetBool("running", false); } if (numero == 1) { anim.SetTrigger("ataque1"); GameObject Temporary_Bullet_Handler2; Temporary_Bullet_Handler2 = Instantiate(prefab2, spawpoint2.transform.position, spawpoint2.transform.rotation) as GameObject; Temporary_Bullet_Handler2.transform.Rotate(Vector3.left * 90); Rigidbody Temporary_RigidBody2; Temporary_RigidBody2 = Temporary_Bullet_Handler2.GetComponent <Rigidbody>(); Temporary_RigidBody2.AddForce(transform.forward * speed2); Destroy(Temporary_Bullet_Handler2, 10.0f); numero = 0; sa.SetAudio(Random.Range(41, 43), gameObject.transform); } if (numero == 2) { anim.SetTrigger("ataque2"); GameObject Temporary_Bullet_Handler; Temporary_Bullet_Handler = Instantiate(prefab, spawpoint.transform.position, spawpoint.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 * speed); Destroy(Temporary_Bullet_Handler, 10.0f); numero = 0; sa.SetAudio(44, gameObject.transform); } }
// Update is called once per frame void Update() { //Get Microphone Data loudness = GetAveragedVolume() * sensitivity; Debug.Log(GetAveragedVolume()); Debug.Log(loudness); //Debug.Log(oneWaveSwitch); //Shoot when making sounds if (!oneWaveSwitch) { debunk2 = true; if (loudness > 5 && debunk2 == true) { //The Bullet instantiation happens here. Temporary_Bullet_Handler = Instantiate(SoundBullet, SoundBullet_Emitter.transform.position, SoundBullet_Emitter.transform.rotation) as GameObject; Debug.Log("boom!"); debunk2 = false; oneWaveSwitch = true; //oneWaveSwitch = false; } } else if (oneWaveSwitch) { timer += Time.deltaTime; if (timer > 0.8f) { oneWaveSwitch = false; timer = 0; } } //GameObject Temporary_Bullet_Handler; //Temporary_Bullet_Handler = Instantiate(SoundBullet, SoundBullet_Emitter.transform.position, SoundBullet_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 * SoundBullet_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, 1f); }
// Update is called once per frame void Update() { transform.rotation = ClampRotationAroundXAxis(transform.rotation, minAngle, maxAngle); if (Input.GetKey(KeyCode.Q) || (Input.GetAxis("CannonRight") < 0) || (bulletSlider.value < 0.5)) { transform.Rotate(Vector3.left * Time.deltaTime * CannonSpeed); } if (Input.GetKey(KeyCode.A) || (Input.GetAxis("CannonRight") > 0) || (bulletSlider.value > 0.5)) { transform.Rotate(Vector3.right * Time.deltaTime * CannonSpeed); } bulletTimer -= Time.deltaTime; if (bulletTimer <= 0f) { bulletTimer = 0f; } if (Input.GetKey(KeyCode.Tab) && (bulletTimer == 0f) || (Input.GetKey(KeyCode.JoystickButton5) || (Input.GetAxis("RightTrigger") > 0)) && (bulletTimer == 0f)) { GameObject Temporary_Bullet_Handler; Temporary_Bullet_Handler = Instantiate(bulletInstance, bulletSpawn.transform.position, bulletSpawn.transform.rotation) as GameObject; audioSource.PlayOneShot(impact, 1); bulletTimer = 0.5f; //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.right * 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, 4.0f); } }
public void Shoot() { GameObject Temporary_kogel_handeler; Temporary_kogel_handeler = Instantiate(kogelPrefab, kogelspawn.transform.position, kogelspawn.transform.rotation) as GameObject; Rigidbody Temporary_RigidBody; Temporary_RigidBody = Temporary_kogel_handeler.GetComponent <Rigidbody>(); Temporary_RigidBody.AddForce(transform.forward * kogelspeed); Destroy(Temporary_kogel_handeler, 12.0f); }
public void shoot() { for (int i = 0; i < bulletSpawners.Length; i++) { audioSrc.clip = Shoot; audioSrc.PlayOneShot(Shoot, 0.7f); Rigidbody Temporary_RigidBody; GameObject newBullet = Instantiate(EnemyProjectile, bulletSpawners[0].position, bulletSpawners[i].rotation) as GameObject; Temporary_RigidBody = newBullet.GetComponent <Rigidbody>(); Temporary_RigidBody.AddForce(newBullet.transform.forward * projectileForce); Destroy(newBullet, 10.0f); } lastShot = Time.time; }
void Update() { if (Input.GetMouseButton(0) && !playerRef.isAttacking && playerRef.karma < .3) { playerRef.fireball = true; GameObject Temporary_Bullet_Handler; Temporary_Bullet_Handler = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject; SceneController.bullets.Add(Temporary_Bullet_Handler); 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); } }
void Update() { if (Input.GetButtonDown("Fire1")) { GameObject BulletHolder; BulletHolder = Instantiate(Bullet, transform.position, transform.rotation) as GameObject; BulletHolder.transform.Rotate(Vector3.left * 90); Rigidbody Temporary_RigidBody; Temporary_RigidBody = BulletHolder.GetComponent <Rigidbody>(); Temporary_RigidBody.AddForce(transform.forward * Force); Destroy(BulletHolder, 2.0f); } }
public void SpawnsmallBullet() { 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_Forword_Force); Temporary_RigidBody.velocity = transform.TransformDirection(new Vector3(0, Bullet_direction, 0)); Destroy(Temporary_Bullet_Handler, 7.0f); }
void fireBullet() { //The Bullet instantiation GameObject Temporary_Bullet_Handler; Temporary_Bullet_Handler = Instantiate(Bullet, bulletHole.transform.position, bulletHole.transform.rotation) as GameObject; //Retrieve the Rigidbody component from the instantiated Bullet and control it. Rigidbody Temporary_RigidBody; Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody> (); //pushed the bullet forward Temporary_RigidBody.AddForce(transform.up * BulletVelocity); }
void Update() { if (Input.GetKey("space") && Time.time >= nextTimeToFire || Input.GetButton("Fire1") && Time.time >= nextTimeToFire) { nextTimeToFire = Time.time + 1f / fireRate; //The Bullet instantiation happens here. GameObject tempBullet; tempBullet = Instantiate(Bullet, Emitter.transform.position, Emitter.transform.rotation) as GameObject; tempBullet.transform.Rotate(Vector3.left * 90); Rigidbody Temporary_RigidBody; Temporary_RigidBody = tempBullet.GetComponent <Rigidbody>(); Temporary_RigidBody.AddForce(transform.forward * Bullet_Forward_Force); Destroy(tempBullet, 8.0f); } }
private void _SpawnBullet() { GameObject Temporary_Bullet_Handler; Temporary_Bullet_Handler = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation); //Temporary_Bullet_Handler.transform.localPosition += new Vector3(directionX * Bullet_Forward_Force, directionY * Bullet_Forward_Force); 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(new Vector3(Random.Range(-1f, 1f) * Bullet_Forward_Force, Random.Range(-1f, 1f) * Bullet_Forward_Force), ForceMode2D.Impulse); }
IEnumerator PowerAttack() { Attacked = true; anim.SetTrigger("StrongAttack"); audioSrc.PlayOneShot(fire); powCount.RemoveMagicCounter(1); Rigidbody Temporary_RigidBody; 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); Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>(); Temporary_RigidBody.AddForce(CameraPosition.transform.forward * Bullet_Forward_Force); yield return(new WaitForSeconds(3)); }
void PuckPistol() { GameObject Temporary_Bullet_Handler; Rigidbody Temporary_RigidBody; Temporary_Bullet_Handler = Instantiate(Bullet, ShootPlace.transform.position, ShootPlace.transform.rotation) as GameObject; Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>(); Temporary_RigidBody.AddForce(transform.forward * Bullet_Force); audioSource.clip = puckPistolShot; Destroy(Temporary_Bullet_Handler, 4.0f); }
void FireBullet() { SoundManagerScript.PlaySound("laser"); //laser sound GameObject Temporary_Bullet_Handler; //make a new bullet Temporary_Bullet_Handler = Instantiate(BulletPrefab, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject; Rigidbody2D Temporary_RigidBody; //lets add some force Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody2D>(); Temporary_RigidBody.AddForce(transform.right * BulletSpeed); Destroy(Temporary_Bullet_Handler, 3.0f); //bye bye in 3 seconds }
void Fire() { if (Time.time > nextFire) { nextFire = Time.time + FireRate; GameObject Temporary_Bullet_Handler; Temporary_Bullet_Handler = Instantiate(Shot, ShotSpawn.transform.position, ShotSpawn.transform.rotation) as GameObject; Shot.GetComponent <Rigidbody>().AddForce(transform.forward * Shot_Forward); Rigidbody Temporary_RigidBody; Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>(); Temporary_RigidBody.AddForce(transform.forward * Shot_Forward); } }
void aoeBurst(int offsetAngle) { GameObject bullet; bullet = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject; bullet.transform.Rotate(new Vector3(-90, 0, 0 + offsetAngle)); Rigidbody Temporary_RigidBody; Temporary_RigidBody = bullet.GetComponent <Rigidbody>(); Temporary_RigidBody.AddForce(bullet.transform.rotation * bullet.transform.forward * Bullet_Forward_Force / 2); Destroy(bullet, 5.0f); }
// Update is called once per frame void Update() { if (Input.GetButton("Tap")) { //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, 7.0f); } var rms = MicInput.MicLoudness * Multiply; if (rms > 6) { //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, 7.0f); } }
public void Shoot() { GameObject Temporary_Bullet_Handler; Temporary_Bullet_Handler = Instantiate(Kogel, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject; Temporary_Bullet_Handler.transform.Rotate(Vector3.left * 0); Rigidbody Temporary_RigidBody; Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>(); Temporary_RigidBody.AddForce(transform.forward * Bullet_force); Destroy(Temporary_Bullet_Handler, 5f); timer = 0; }
// Update is called once per frame void Update() { if (Input.GetKeyDown("mouse 0")) { // Spawn Bullet GameObject spawnedBullet; spawnedBullet = Instantiate(bullet, bulletSpawn.transform.position, bulletSpawn.transform.rotation) as GameObject; SoundManager.Play("ShootSound"); Rigidbody Temporary_RigidBody; Temporary_RigidBody = spawnedBullet.GetComponent <Rigidbody>(); Temporary_RigidBody.AddForce(transform.forward * bulletSpeed); Destroy(spawnedBullet, 1.8f); } }
// Update is called once per frame void OnTriggerEnter(Collider other) { if (other.tag == "Earthquake") { GameObject TemporaryShockwaveHandler; TemporaryShockwaveHandler = Instantiate(Shockwave, EQ_Emitter.transform.position, EQ_Emitter.transform.rotation) as GameObject; Rigidbody Temporary_RigidBody; Temporary_RigidBody = TemporaryShockwaveHandler.GetComponent <Rigidbody>(); Temporary_RigidBody.AddForce(transform.right * ShockwaveForwardForce); Destroy(TemporaryShockwaveHandler, 5.0f); Destroy(other.gameObject); } }
// Update is called once per frame void Update() { shotTime -= Time.deltaTime; if (shotTime <= 0) { Shoot.Play(); 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); Rigidbody Temporary_RigidBody; Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>(); Temporary_RigidBody.AddForce(transform.forward * Bullet_Forward_Force); Destroy(Temporary_Bullet_Handler, 10.0f); shotTime = shotTime + 2; } }
// Update is called once per frame void Update() { Bullet_Forward_Force = Random.Range(forceMin, forceMax); chanceNumber = Random.Range(chanceMin, chanceMax); if (chanceNumber < chanceThresh) { if (chanceNumber <= chanceThresh2) { Bullet = bigCollectable; } if (chanceNumber > chanceThresh2) { Bullet = collectable; } } if (chanceNumber > chanceThresh) { Bullet = obstacle; } if (canShoot == true) { //The Bullet Instantiation happens here. GameObject Temporary_Bullet_handler; Temporary_Bullet_handler = Instantiate(Bullet, bulletEmitter1.transform.position, bulletEmitter1.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 * Bullet_Forward_Force, 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, bulletLifetime); canShoot = false; StartCoroutine(ShootWarmup()); } }
// Update is called once per frame void Update() { if (canShoot) { //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. if (ShootDirectionOnZ) { Temporary_RigidBody.AddForce(new Vector3(0, 0, -1) * Bullet_Forward_Force); } else { if (ReverseShootDirectionOnX) { Temporary_RigidBody.AddForce(new Vector3(1, 0, 0) * Bullet_Forward_Force); } else { Temporary_RigidBody.AddForce(new Vector3(-1, 0, 0) * 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); canShoot = false; Invoke("ShootAgain", RateOfFire); } }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { //The Lazer Instantiation happens here GameObject Temporary_Lazer_Handler; Temporary_Lazer_Handler = Instantiate(Lazer, Lazer_Emitter.transform.position, Lazer_Emitter.transform.rotation) as GameObject; //sometimes lazers may appear rotated incorrectly due to the way its pivot was set from the original modeling backage. //This is EASILY corrected here, you might have to rotate it from a different axis and or angle based on your particular mesh. Temporary_Lazer_Handler.transform.Rotate(Vector3.left * 90); //Retrieve the Rigidbody component from the instantiated Lazer and control it. Rigidbody Temporary_RigidBody; Temporary_RigidBody = Temporary_Lazer_Handler.GetComponent <Rigidbody>(); //Tell the bullet to be "pushed" forward by an amount set by Lazer_Forward_Force. Temporary_RigidBody.AddForce(transform.forward * Lazer_Forward_Force); //Basic Clean Up, set the Lazers to self destruct after 3 seconds Destroy(Temporary_Lazer_Handler, 3.0f); } else if (Input.GetButtonDown("RBumper_Button")) { //repeat the process for the mouse button //The Lazer Instantiation happens here GameObject Temporary_Lazer_Handler; Temporary_Lazer_Handler = Instantiate(Lazer, Lazer_Emitter.transform.position, Lazer_Emitter.transform.rotation) as GameObject; //sometimes lazers may appear rotated incorrectly due to the way its pivot was set from the original modeling backage. //This is EASILY corrected here, you might have to rotate it from a different axis and or angle based on your particular mesh. Temporary_Lazer_Handler.transform.Rotate(Vector3.left * 90); //Retrieve the Rigidbody component from the instantiated Lazer and control it. Rigidbody Temporary_RigidBody; Temporary_RigidBody = Temporary_Lazer_Handler.GetComponent <Rigidbody>(); //Tell the bullet to be "pushed" forward by an amount set by Lazer_Forward_Force. Temporary_RigidBody.AddForce(transform.forward * Lazer_Forward_Force); //Basic Clean Up, set the Lazers to self destruct after 3 seconds Destroy(Temporary_Lazer_Handler, 3.0f); } }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { //The Bullet instantiation. GameObject BulletGameObject; Temporary_Bullet_Handler = Instantiate(bullet, bulletEmitter.transform.position, bulletEmitter.transform.rotation) as GameObject; //Retrieve the Rigidbody component from the instantiated Bullet and control it. Rigidbody Temporary_RigidBody; Temporary_RigidBody = BulletGameObject.GetComponent <Rigidbody>(); //bullet being pushed Temporary_RigidBody.AddForce(transform.forward * bulletForwardForce); //Destroy the unncessary components Destroy(BulletGameObject, 3f); } }
//public float Bullet_Forward_Force2shotty; void Update() { if (Input.GetKeyDown(KeyCode.Mouse0)) { Vector3 aimSpot = camera.transform.position; aimSpot += camera.transform.forward * 50.0f; //The Bullet instantiation happens here. GameObject Temporary_Bullet_Handler; Temporary_Bullet_Handler = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject; Bullet.transform.LookAt(aimSpot); //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>(); Temporary_RigidBody.AddForce(-transform.forward * Bullet_Forward_Force); Destroy(Temporary_Bullet_Handler, 0.05f); } }