public void AttackFrame() { if (m_CurrentTargetCharacterData == null) { m_ClearPostAttack = false; return; } //if we can't reach the target anymore when it's time to damage, then that attack miss. if (m_CharacterData.CanAttackReach(m_CurrentTargetCharacterData)) { m_CharacterData.Attack(m_CurrentTargetCharacterData); var attackPos = m_CurrentTargetCharacterData.transform.position + transform.up * 0.5f; VFXManager.PlayVFX(VFXType.Hit, attackPos); SFXManager.PlaySound(m_CharacterAudio.UseType, new SFXManager.PlayData() { Clip = m_CharacterData.Equipment.Weapon.GetHitSound(), PitchMin = 0.8f, PitchMax = 1.2f, Position = attackPos }); } if (m_ClearPostAttack) { m_ClearPostAttack = false; m_CurrentTargetCharacterData = null; m_TargetInteractable = null; } m_CurrentState = State.DEFAULT; }
public void AttackFrame() { CharacterData playerData = CharacterControl.Instance.Data; //if we can't reach the player anymore when it's time to damage, then that attack miss. if (!m_CharacterData.CanAttackReach(playerData)) { return; } m_CharacterData.Attack(playerData); }
public void Update() { // Key and mouse movement control // if (!isDead) { float horisontal = Input.GetAxis("Horizontal"); float vertical = Input.GetAxis("Vertical"); Vector3 movement = new Vector3(horisontal, 0f, vertical); if (movement.normalized.magnitude >= 0.1f) { Vector3 moveDestination = transform.position + movement; agent.destination = moveDestination; if (CurrentState == State.ATTACKING) { CurrentState = State.DEFAULT; currentTargetCharacterData = null; } } else { RaycastHit hit; if (Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition), out hit, 50, ClickableLayer.value)) { bool enemyHit = false; if (hit.collider.gameObject.tag == "enemy") { enemyHit = true; } if (Input.GetMouseButtonDown(0)) { if (enemyHit) { Transform enemyPos = hit.collider.gameObject.transform; agent.destination = enemyPos.position; if (currentTargetCharacterData) { lastTegetCharacterData = currentTargetCharacterData; } currentTargetCharacterData = enemyPos.GetComponent <UnitData>(); } else { agent.destination = hit.point; lastTegetCharacterData = currentTargetCharacterData; currentTargetCharacterData = null; if (CurrentState == State.ATTACKING) { CurrentState = State.DEFAULT; currentTargetCharacterData = null; } } } } } if (currentTargetCharacterData && characterData.CanAttackReach(currentTargetCharacterData) && CurrentState != State.ATTACKING) { agent.Stop(); agent.ResetPath(); var targetDirection = (currentTargetCharacterData.transform.position - transform.position).normalized; targetDirection.y = 0f; transform.rotation = Quaternion.LookRotation(targetDirection); CurrentState = State.ATTACKING; } if (CurrentState == State.ATTACKING) { characterData.Attack(currentTargetCharacterData); if (!characterData.TargetIsLive(currentTargetCharacterData)) { CurrentState = State.DEFAULT; currentTargetCharacterData = null; } } } //Respawn else if (isDead) { CurrentState = State.DEFAULT; deathTimer += Time.deltaTime; if (deathTimer > 3.0f) { GoToRespawn(); } return; } if (characterData.Stats.CurrentHealth == 0) { isDead = true; _renderer.enabled = false; characterData.StartingWeapon.GetComponentInChildren <Renderer>().enabled = false; deathTimer = 0.0f; } // }