// Update is called once per frame void Update() { if (this.transform.position.y >= GameObject.Find("Bounding Box").GetComponent <boundingBox>().ylowerlimit) { if (DateTime.Now >= interval) { GameObject TempBullet; TempBullet = Instantiate(Bullet, this.transform.position, this.transform.rotation) as GameObject; Rigidbody2D TempRigidbody; TempRigidbody = TempBullet.GetComponent <Rigidbody2D>(); TempRigidbody.AddForce(-transform.right * BulletSpeed); TempRigidbody.AddForce(transform.up * 85); //self destruct code in EnemyProjectileDamage (attached to projectile) TempBullet = Instantiate(Bullet, this.transform.position, this.transform.rotation) as GameObject; TempRigidbody = TempBullet.GetComponent <Rigidbody2D>(); TempRigidbody.AddForce(transform.right * BulletSpeed); TempRigidbody.AddForce(transform.up * 85); interval = DateTime.Now.AddSeconds(timeBetweenBullets); } } }
public void Shoot() { GameObject TempBullet; TempBullet = Instantiate(bullet, muzzle.transform.position, muzzle.transform.rotation) as GameObject; Rigidbody TempRigidbody; TempRigidbody = TempBullet.GetComponent <Rigidbody> (); TempRigidbody.AddRelativeForce(Vector3.forward * bulletforce); //Destroy (TempBullet, 10.0f); }
void Update() { //GameObject[] gameObjects; //gameObjects = GameObject.FindGameObjectsWithTag("enemy"); /*if(gameObjects.Length == 0) * {*/ transform.Translate(1 * horizontalSpeed * Time.deltaTime, Time.deltaTime * verticalSpeed, 0); //} if (this.transform.position.y < 3.0f) { verticalSpeed = 0.0f; } if (GameObject.Find("StageOneBoss(Clone)").transform.position.x > 8f) { horizontalSpeed = -6.0f; } if (GameObject.Find("StageOneBoss(Clone)").transform.position.x < -8f) { horizontalSpeed = 6.0f; } if (this.GetComponent <EnemyProperties>().health <= 300) //for rage mode, faster shooting rate { this.GetComponent <EnemyShootBullet>().timeBetweenBullets = 2.0f; spawnEnemy(Time.time); if (Time.time - timeSinceLastBullet > shootInterval) { GameObject TempBullet; TempBullet = Instantiate(currentProjectile, this.transform.position, this.transform.rotation * Quaternion.Euler(0, 0, -45)) as GameObject; GameObject TempBullet1; TempBullet1 = Instantiate(currentProjectile, this.transform.position, this.transform.rotation * Quaternion.Euler(0, 0, 45)) as GameObject; Rigidbody2D TempRigidbody; TempRigidbody = TempBullet.GetComponent <Rigidbody2D>(); Rigidbody2D TempRigidbody1; TempRigidbody1 = TempBullet1.GetComponent <Rigidbody2D>(); TempRigidbody.AddForce(-TempRigidbody.transform.up * 230f); TempRigidbody1.AddForce(-TempRigidbody1.transform.up * 230f); timeSinceLastBullet = Time.time; } } }
void Shooting() { if (loaded) { Unload(); GameObject TemporaryBullethandler; TemporaryBullethandler = gameObject.transform.GetChild((gameObject.transform.childCount - 1)).gameObject; TemporaryBullethandler.transform.parent = null; TemporaryBullethandler.GetComponent <Rigidbody>().useGravity = true; TemporaryBullethandler.GetComponent <Rigidbody>().detectCollisions = true; //Instantiate(bullet,bulletEmitter.transform.position, bulletEmitter.transform.rotation) as GameObject; TemporaryBullethandler.transform.Rotate(Vector3.left * 90); Rigidbody TempRigidbody; TempRigidbody = TemporaryBullethandler.GetComponent <Rigidbody>(); TempRigidbody.AddForce(transform.forward * (bulletSpeed + moveSpeed)); if (bullet.name == "bullet" || bullet.name == "Bomb") { TempRigidbody.AddForce(transform.up * (250)); } TemporaryBullethandler.GetComponent <Bullet>().collisionEnable = true; Destroy(TemporaryBullethandler, 6.0f); if (bulletSpeed <= 1500) { ShootSound.Play(); } else if (bulletSpeed <= 2000) { UziSound.Play(); } else { SniperSound.Play(); } } else { //print("shooting is on cooldown"); //ReloadSound.Play(); } }
void Shoot() { //TempBullet.transform.position += (bulletdirection * Bulletforce ) * Time.deltaTime; //Destroy (TempBullet, 10.0f); if (playerDeath.Dead) { CancelInvoke(); //Destroy (TempBullet); } else { GameObject TempBullet; TempBullet = Instantiate(Bullet, transform.position, transform.rotation) as GameObject; Rigidbody TempRigidbody; TempRigidbody = TempBullet.GetComponent <Rigidbody> (); Vector3 bulletdirection = (TempBullet.transform.position - Player.position).normalized; TempRigidbody.AddRelativeForce(bulletdirection * -Bulletforce); } }
protected virtual void Move(Vector3 direction) { if (direction.magnitude != 0) { if (direction.magnitude > 1) { direction = direction.normalized; } var targetSpeed = GetMoveSpeed() * (isDashing ? dashMoveSpeedMultiplier : 1f); var targetVelocity = direction * targetSpeed; // Apply a force that attempts to reach our target velocity Vector3 velocity = TempRigidbody.velocity; Vector3 velocityChange = (targetVelocity - velocity); velocityChange.x = Mathf.Clamp(velocityChange.x, -targetSpeed, targetSpeed); velocityChange.y = 0; velocityChange.z = Mathf.Clamp(velocityChange.z, -targetSpeed, targetSpeed); TempRigidbody.AddForce(velocityChange, ForceMode.VelocityChange); } }
// Update is called once per frame void Update() { if (!shootCD) { Timer += Time.deltaTime; if (Timer >= shootTimer) { Timer = 0; shootCD = true; ShootSign.GetComponent <Image>().color = Color.green; } } if (Input.GetButtonDown("ShootKey02")) { if (shootCD) { shootCD = false; ShootSign.GetComponent <Image>().color = Color.red; GameObject TemporaryBullethandler; TemporaryBullethandler = Instantiate(bullet, bulletEmitter.transform.position, bulletEmitter.transform.rotation) as GameObject; TemporaryBullethandler.transform.Rotate(Vector3.left * 90); Rigidbody TempRigidbody; TempRigidbody = TemporaryBullethandler.GetComponent <Rigidbody>(); TempRigidbody.AddForce(transform.forward * bulletSpeed); Destroy(TemporaryBullethandler, 7.0f); } else { print("shooting is on cooldown"); } } }