void Update() { if (!LevelController.Instance.GameRunnig || dead) { return; } if (Target != null) { // TODO: Rotate it Properly Vector3 dir = Target.position - transform.position; float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg + 270; transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward); // Movement if (!shooting) { if (Vector3.Distance(Target.position, transform.position) >= BulletRangeMin) { transform.position = Vector3.MoveTowards(transform.position, Target.position, Speed * Time.deltaTime); } else { shooting = true; } } else { if (Vector3.Distance(Target.position, transform.position) >= BulletRangeMax) { shooting = false; } if (nextBullet <= Time.time) { myGun.Shoot(); m_Animator.SetTrigger("Shoot"); nextBullet = Time.time + CooldownTime; } } } else { ChooseTarget(); } }
public void TryToShoot(NPCStateData stateData, float delayBeforeFirstShot) { if (stateData.initializing == true) { timeSinceShootingStart = 0; } if (timeSinceShootingStart < delayBeforeFirstShot) { timeSinceShootingStart += Time.deltaTime; return; } if (rateOfFireCoutner > 1 / equippedGun.fireRate) { equippedGun.Shoot(); rateOfFireCoutner = 0; } }
// Update is called once per frame void Update() { rateOfFireCoutner += Time.deltaTime; if (hasShot == false || fullAuto == true) //check for full/semi auto settings, { if (isShooting && rateOfFireCoutner > 1 / equippedGun.fireRate) //shoot if 1. player is pulling trigger 2. PLayer has ammo 3. Enough time has passed since the last shot { if (supplyManager.UseSupplies(suppliesPerShot)) { equippedGun.Shoot(); rateOfFireCoutner = 0; hasShot = true; } else { equippedGun.PlayNoAmmoSound(); rateOfFireCoutner = 0; hasShot = true; } } } }