void Update() { if (target == null) { target = Player2D.instance.transform; if (!target.gameObject.activeSelf) { return; } } if (Vector3.Distance(transform.position, target.position) <= shootingDistance) { bulletDelayTimer -= Time.deltaTime; if (bulletDelayTimer <= 0f) { bulletDelayIndex++; if (bulletDelays.Length == 1) { bulletDelayIndex = 0; } else { bulletDelayIndex %= bulletDelays.Length; } bulletDelayTimer = bulletDelays[bulletDelayIndex]; GameObject bullet = Instantiate(bulletPrefab, transform.position, Quaternion.identity); BulletMovementController bulletMovementController = bullet.GetComponent <BulletMovementController>(); bulletMovementController.targetPosition = target.position; bulletMovementController.creator = gameObject; } } }
void Update() { float CurrentTime = Time.time; if (CurrentTime - StartTime > NewBulletTime) { StartTime = CurrentTime; AddBullet(); } int direction = Character.Direction; //Debug.Log ("direction: "+direction); if ((Input.GetKeyDown(KeyCode.F) || Input.GetKeyDown(KeyCode.Q)) && NumOfBullets > 0) { GameObject bullet = (GameObject)Instantiate(bulletTransform, transform.position, Quaternion.identity); BulletMovementController bulletMovementController = bullet.GetComponent <BulletMovementController> (); bulletMovementController.Direction = direction; gunshotSound.Play(); DeleteBullet(); } NumOfBulletsText.text = NumOfBullets.ToString(); }