public void Update() { if (!item) { item = this.GetComponent <OSItem> (); return; } if (!bullet) { bullet = item.ammunition.projectile; } if (fireTimer > 0) { fireTimer -= Time.deltaTime; } if (flashTimer > 0) { flashTimer -= Time.deltaTime; } if (muzzleFlash) { if (flashTimer > 0 && !muzzleFlash.activeSelf) { muzzleFlash.SetActive(true); if (muzzleFlash.particleSystem) { muzzleFlash.particleSystem.Play(); } } else if (flashTimer <= 0 && muzzleFlash.activeSelf) { muzzleFlash.SetActive(false); } } if (projectileTypeThreshold > 0) { if (Time.timeScale >= projectileTypeThreshold) { projectileType = OSProjectileType.Raycast; } else if (bullet) { projectileType = OSProjectileType.Prefab; } } }
public static void Fire ( OSProjectile p, float range, Vector3 position, Ray ray, OSFirearm firearm ) { OSProjectile projectile = (OSProjectile) Instantiate ( p ); projectile.lifetime = range / projectile.speed; projectile.transform.position = position; projectile.firearm = firearm; RaycastHit hit = new RaycastHit(); if ( Physics.Raycast ( ray, out hit, Mathf.Infinity, projectile.layerMask ) ) { projectile.transform.LookAt ( hit.point ); } }
public static void Fire(OSProjectile p, float range, Vector3 position, Ray ray, OSFirearm firearm) { OSProjectile projectile = (OSProjectile)Instantiate(p); projectile.lifetime = range / projectile.speed; projectile.transform.position = position; projectile.firearm = firearm; RaycastHit hit = new RaycastHit(); if (Physics.Raycast(ray, out hit, Mathf.Infinity, projectile.layerMask)) { projectile.transform.LookAt(hit.point); } }
public void Update () { if ( !item ) { item = this.GetComponent< OSItem > (); return; } if ( !bullet ) { bullet = item.ammunition.projectile; } if ( fireTimer > 0 ) { fireTimer -= Time.deltaTime; } if ( flashTimer > 0 ) { flashTimer -= Time.deltaTime; } if ( muzzleFlash ) { if ( flashTimer > 0 && !muzzleFlash.activeSelf ) { muzzleFlash.SetActive ( true ); if ( muzzleFlash.particleSystem ) { muzzleFlash.particleSystem.Play (); } } else if ( flashTimer <= 0 && muzzleFlash.activeSelf ) { muzzleFlash.SetActive ( false ); } } if ( projectileTypeThreshold > 0 ) { if ( Time.timeScale >= projectileTypeThreshold ) { projectileType = OSProjectileType.Raycast; } else if ( bullet ) { projectileType = OSProjectileType.Prefab; } } }
public void Fire() { if (fireTimer > 0) { return; } fireTimer = 1 / firingRate; if (item.ammunition.clip > 0 || item.ammunition.max <= 0 || !item.ammunition.enabled) { flashTimer = muzzleFlashDuration; Ray ray; Vector3 pos; if (muzzleFlash) { pos = muzzleFlash.transform.position; } else { pos = this.transform.position; } item.PlayAnimation(firingAnimationIndex); if (aimWithMainCamera) { ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward); } else { ray = new Ray(pos, this.transform.forward); } Vector3 perfectDir = ray.direction; float acc = accuracy; if (projectileType == OSProjectileType.Prefab && bullet) { for (int i = 0; i < item.ammunition.spread; i++) { ray.direction = ScatterDirection(perfectDir, acc); OSProjectile.Fire(bullet, range, pos, ray, this); } } else if (projectileType == OSProjectileType.Raycast) { RaycastHit hit = new RaycastHit(); for (int i = 0; i < item.ammunition.spread; i++) { ray.direction = ScatterDirection(perfectDir, acc); if (Physics.Raycast(ray, out hit, range)) { hit.collider.gameObject.SendMessage("OnProjectileHit", this, SendMessageOptions.DontRequireReceiver); if (hit.collider.rigidbody) { hit.collider.rigidbody.AddForce(ray.direction.normalized * damage * 100); } } } } item.PlaySound(firingSoundIndex); item.ammunition.clip -= 1; if (item.ammunition.clip <= 0) { Reload(); } } else if (item.ammunition.value > 0) { Reload(); } else { item.PlaySound(emptySoundIndex); } }