private void FixedUpdate() { if (Cursor.lockState != CursorLockMode.Locked) { return; } float dt = Time.fixedDeltaTime; isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask); if (isGrounded && velocity.y < 0) { velocity.y = -2f; } if (mouseMovement.magnitude > 0.1f) { transform.Rotate(Vector3.up * mouseMovement.x * mouseSensibility * dt); cameraRotation = Mathf.Clamp(cameraRotation - mouseMovement.y * mouseSensibility * dt, -90f, 90f); cameraTransform.localRotation = Quaternion.Euler(cameraRotation, 0f, 0f); } move = transform.right * movementDirection.x + transform.forward * movementDirection.y; controller.Move(move * movementVelocity * dt); moving = false; if (move.magnitude != 0) { moving = true; if (isGrounded) { //Simular atraso dos passos stepTimer += Time.deltaTime; if (stepTimer >= stepTime) { eventEmitter.PlayEventInstance(eventIndex); stepTimer = 0f; } } else { //Forçar som de passo na volta do pulo stepTimer = 0.2f; } } velocity.y += gravity * dt; controller.Move(velocity * dt); }
public void Shoot(Vector3 origin, Vector3 dir) { if (timer <= 0) { //bullet = Instantiate(bulletPrefab, transform.position, Quaternion.identity); timer = cooldown; Debug.DrawRay(transform.position, dir); // eventEmitter.PlaySFXOneShot(FMODEvents.events[(int)FMODEvents.Guns.LASER_SHOT], transform.position); int eventIndex; if (gameObject.name.Contains("glock 1")) { eventIndex = eventEmitter.StartEventThatFollows(FMODEvents.events[(int)FMODEvents.Guns.GLOCK_SHOT], gameObject, gameObject.GetComponent <Rigidbody>()); } else { eventIndex = eventEmitter.StartEventThatFollows(FMODEvents.events[(int)FMODEvents.Guns.LASER_SHOT], gameObject, gameObject.GetComponent <Rigidbody>()); } eventEmitter.PlayEventInstance(eventIndex); particles.Play(); RaycastHit hit; bool onHit = Physics.Raycast(origin, dir, out hit, 1000f, layermask); if (onHit) { line.enabled = true; Vector3[] points = { startOfLine.transform.position, hit.point }; line.SetPositions(points); if (isControllable) { Debug.Log(hit.collider.gameObject.name); hit.collider.GetComponent <HP>()?.photonView.RPC("Damage", Photon.Pun.RpcTarget.All, damage); if (hit.collider.GetComponent <HP>()?.IsDead() ?? false) { GetComponentInParent <Score>()?.photonView.RPC("AddPoint", RpcTarget.All); } } lineTimer = 0.3f; } } }
// Update is called once per frame void Update() { eventEmitter.Set3DAttributes(eventIndex, gameObject); if (shootWeapon) { playerWeapon.Shoot(cameraTransform.position, cameraTransform.forward); Debug.Log("Other Pew"); } if (!moving || !isGrounded) { ParticleSystem.EmissionModule em = particles.emission; em.enabled = false; } else { ParticleSystem.EmissionModule em = particles.emission; em.enabled = true; } if (move.magnitude != 0) { moving = true; if (isGrounded) { //Simular atraso dos passos stepTimer += Time.deltaTime; if (stepTimer >= stepTime) { eventEmitter.PlayEventInstance(eventIndex); stepTimer = 0f; } } else { //Forçar som de passo na volta do pulo stepTimer = 0.4f; } } }
// Update is called once per frame void Update() { if (!photonView.IsMine) { return; } List <GameObject> enemy; enemy = new List <GameObject>(); foreach (Player p in PhotonNetwork.PlayerListOthers) { enemy.Add((GameObject)p.TagObject); } GameObject nearestEnemy = null; float distance = Mathf.Infinity; foreach (GameObject go in enemy) { if (go) { float goDist = Vector3.Distance(transform.position, go.transform.position); if (goDist < distance) { distance = goDist; nearestEnemy = go; } } else { continue; } } if (!nearestEnemy) { return; } distance = Vector3.Distance(transform.position, nearestEnemy.transform.position); //Parâmetro vai de 0 a 10, dividir valor por 3 distance = distance / 3; if (distance <= 10) { if (!started) { started = true; // print(FMODEvents.events[(int)FMODEvents.General.ENEMY_CLOSE]); // eventIndex = eventEmitter.StartEventInstance(FMODEvents.events[(int)FMODEvents.General.ITEM_IDLE]); eventIndex = eventEmitter.StartEventThatFollows(FMODEvents.events[(int)FMODEvents.General.ENEMY_CLOSE], gameObject, GetComponentInChildren <Rigidbody>()); eventEmitter.PlayEventInstance(eventIndex); } else { eventEmitter.SetLocalParameter(FMODEvents.LocalParameters.Distance.ToString(), distance, eventIndex); } } else { if (started) { eventEmitter.StopInstance(eventIndex, true); started = false; } } // print(distance); }