void Update() { if (!MoveAllowed.Value) { return; } DashElaspedTime.ApplyChange(Time.deltaTime); if (IsDashing.Value) { if (DashElaspedTime.Value >= dashTime) { IsDashing.SetValue(false); } } else { if (Inputs.Actions.Gameplay.Dash.ReadValue <float>() > 0.0f && DashElaspedTime.Value > DashRate.Value) { IsDashing.SetValue(true); DashElaspedTime.SetValue(0); } Direction.SetValue(Inputs.Actions.Gameplay.Move.ReadValue <Vector2>()); } }
void Update() { FireElaspedTime.ApplyChange(Time.deltaTime); if (PV == null) { PV = GetComponent <PhotonView>(); } Vector2 direction = Inputs.Actions.Gameplay.FireDirection.ReadValue <Vector2>(); bool hasTriggered = Inputs.Actions.Gameplay.Fire.ReadValue <float>() > 0.1f; if (hasTriggered || direction.magnitude > 0.1f) { // in case of click, we need to compute the direction using the mouse position if (direction.magnitude <= 0.1f) { direction = (FollowCamera.GetWorldPoint() - new Vector2(transform.position.x, transform.position.y)); } direction.Normalize(); if (FireAllowed.Value && !IsDead.Value && FireElaspedTime.Value > FireRate.Value) { FireElaspedTime.SetValue(0.0f); // adding a bit of the direction vector to the position so the bullet does spawn at the character center Vector3 position = transform.position + new Vector3(direction.x, direction.y, transform.position.z) * 0.9f; proxy.Fire(PhotonNetwork.LocalPlayer.ActorNumber, position, direction); weaponAnimator.SetTrigger("Fire"); } } Vector3 cameraWorldPosition = new Vector3(FollowCamera.GetWorldPoint().x, FollowCamera.GetWorldPoint().y, weaponAnimator.transform.position.z); if (cameraWorldPosition.x < weaponAnimator.transform.position.x) { weaponAnimator.GetComponent <SpriteRenderer>().flipX = true; weaponAnimator.transform.position = gunPos2.position; weaponAnimator.transform.right = weaponAnimator.transform.position - cameraWorldPosition; } else { weaponAnimator.GetComponent <SpriteRenderer>().flipX = false; weaponAnimator.transform.position = gunPos1.position; weaponAnimator.transform.right = cameraWorldPosition - weaponAnimator.transform.position; } }