private void Shoot() { transform.Rotate(0f, Input.GetAxis("Mouse X") * sensetive, 0f); animHero.SetTrigger("Shoot"); if (Input.GetMouseButton(0) & shootTime <= 0) { Rigidbody BulletInstance; BulletInstance = Instantiate(bullet, spawnPoint.position, spawnPoint.rotation) as Rigidbody; BulletInstance.AddForce(spawnPoint.forward * shootForce); shootTime = speedShot; } if (shootTime > 0) { shootTime -= Time.deltaTime; } }
// Update is called once per frame void Update() { float moveH = Input.GetAxis("Horizontal"); float moveV = Input.GetAxis("Vertical"); if (Input.GetKey(KeyCode.UpArrow)) { Vector3 PosisiPlayer = transform.position; PosisiPlayer.z += 0.01f; transform.position = PosisiPlayer; movex = Input.GetAxis("Horizontal"); Anim.SetFloat("movex", movex); movey = Input.GetAxis("Vertical"); Anim.SetFloat("movey", movey); transform.Translate(movespeed * moveH * Time.deltaTime, 0f, movespeed * moveV * Time.deltaTime); } else if (Input.GetKey(KeyCode.DownArrow)) { Vector3 PosisiPlayer = transform.position; PosisiPlayer.z -= 0.01f; transform.position = PosisiPlayer; movex = Input.GetAxis("Horizontal"); Anim.SetFloat("movex", movex); movey = Input.GetAxis("Vertical"); Anim.SetFloat("movey", movey); transform.Translate(movespeed * moveH * Time.deltaTime, 0f, movespeed * moveV * Time.deltaTime); } Rigidbody BulletInstance; if (Input.GetButtonDown("Fire1")) { BulletInstance = Instantiate(test, target.position, target.rotation) as Rigidbody; BulletInstance.AddForce(target.forward * 2000); } else if (Input.GetButtonDown("Fire2")) { BulletInstance = Instantiate(test2, target.position, target.rotation) as Rigidbody; BulletInstance.AddForce(target.forward * 1300); } }
private void Shoot() { if (Input.GetMouseButton(0) & _reloadTimer <= 0 & _shootTimer <= 0 & ammoInMagazine != 0) { { Rigidbody BulletInstance; BulletInstance = Instantiate(bullet, spawnPoint.position, spawnPoint.rotation); BulletInstance.AddForce(spawnPoint.forward * force); for (int i = 0; i < particleSystem.Length; i++) { particleSystem[i].Play(); } _shootTimer = shootSpeed; ammoInMagazine -= 1; audioSource.PlayOneShot(fireSound); ShootLight(); } } else if (Input.GetMouseButtonDown(0) && ammoInMagazine == 0) { audioSource.PlayOneShot(nullSound); } }