void SE_UpdateEnemyAI() { distanceToPlayer = Vector3.Distance(player.transform.position, transform.position); WeaponSystem weaponSystem = GetComponent <WeaponSystem>(); currentWeaponRange = weaponSystem.GetCurrentWeapon().GetMaxAttackRange(); bool inWeaponCircle = distanceToPlayer <= currentWeaponRange; bool inChaseRing = distanceToPlayer > currentWeaponRange && distanceToPlayer <= chaseRadius; bool outsideChaseRing = distanceToPlayer > chaseRadius; if (outsideChaseRing) { StopAllCoroutines(); weaponSystem.StopAttacking(); StartCoroutine(Patrol()); } if (inChaseRing) { StopAllCoroutines(); weaponSystem.StopAttacking(); StartCoroutine(ChasePlayer()); } if (inWeaponCircle) { StopAllCoroutines(); state = State.attacking; weaponSystem.AttackTarget(player.gameObject); } }
void Update() { currentWeapon = weaponSystem.GetCurrentWeapon(); if (PauseMenu.IsOn) { return; } if (Input.GetAxisRaw("Mouse ScrollWheel") != 0) { currentWeaponIndex += (int)(Input.GetAxisRaw("Mouse ScrollWheel") * 10); if (currentWeaponIndex < 0) { currentWeaponIndex = 1; // TODO Remove hard coded value } if (currentWeaponIndex > 1) { currentWeaponIndex = 0; } Debug.Log(currentWeaponIndex); weaponSystem.EquipWeapon(currentWeaponIndex); } // Look for weapon input switch (currentWeapon.weaponType) { case WeaponConfig.WeaponType.Gun: if (currentWeapon.gun_FireRate <= 0f) { if (Input.GetButtonDown("Fire1")) { ShootGun(); } } else { if (Input.GetButtonDown("Fire1")) { InvokeRepeating("ShootGun", 0f, 1f / currentWeapon.gun_FireRate); } else if (Input.GetButtonUp("Fire1")) { CancelInvoke("ShootGun"); } } break; } }
private void WeaponChanged() { Weapon currentWeapon = weaponSystem.GetCurrentWeapon(); WeaponData data; // If we have a weapon if (currentWeapon != null) { data = currentWeapon.weaponData; durabilityText.text = currentWeapon.GetDurability().ToString(); } // else, fist display else { data = fistData; durabilityText.text = "--"; } weaponImage.sprite = data.UiImage; weaponNameText.text = data.Name; }
// Update is called once per frame void Update() { distanceToPlayer = Vector3.Distance(player.transform.position, transform.position); WeaponSystem weaponSystem = GetComponent <WeaponSystem>(); // No performance issue currentWeaponRange = weaponSystem.GetCurrentWeapon().GetMaxAttackRange(); bool inWeaponRadius = distanceToPlayer <= currentWeaponRange; bool inChaseRadius = distanceToPlayer > currentWeaponRange && distanceToPlayer <= chaseRadius; bool outsideChaseRadius = distanceToPlayer > chaseRadius; if (inWeaponRadius) { print("inWeaponRadius"); StopAllCoroutines(); state = State.attacking; transform.LookAt(player.gameObject.transform); weaponSystem.AttackTarget(player.gameObject); character.GetNavMeshAgent().isStopped = true; character.GetNavMeshAgent().velocity = Vector3.zero; } if (outsideChaseRadius) { print("outsideChaseRadius"); StopAllCoroutines(); StartCoroutine(Patrol()); } if (inChaseRadius) { print("inChaseRadius"); StopAllCoroutines(); weaponSystem.StopAttacking(); character.GetNavMeshAgent().isStopped = false; StartCoroutine(ChasePlayer()); } }