private void Awake() { if (instance != null) { if (instance != this) { DestroyImmediate(gameObject); return; } } instance = this; }
// Update is called once per frame void Update() { if (!IsDead && mIsControlEnabled) { // Interact with the item if (mInteractItem != null && Input.GetKeyDown(KeyCode.F)) { // Interact animation mInteractItem.OnInteractAnimation(_animator); } // Execute action with item if (mCurrentItem != null && Input.GetMouseButtonDown(0)) { // Dont execute click if mouse pointer is over uGUI element if (!EventSystem.current.IsPointerOverGameObject()) { // TODO: Logic which action to execute has to come from the particular item _animator.SetTrigger("attack_1"); } } // Get Input for axis float h = Input.GetAxis("Horizontal"); float v = Input.GetAxis("Vertical"); // Calculate the forward vector Vector3 camForward_Dir = Vector3.Scale(Camera.main.transform.forward, new Vector3(1, 0, 1)).normalized; Vector3 move = v * camForward_Dir + h * Camera.main.transform.right; if (move.magnitude > 1f) { move.Normalize(); } // Calculate the rotation for the player move = transform.InverseTransformDirection(move); // Get Euler angles float turnAmount = Mathf.Atan2(move.x, move.z); transform.Rotate(0, turnAmount * RotationSpeed * Time.deltaTime, 0); if (_characterController.isGrounded) { _moveDirection = transform.forward * move.magnitude; _moveDirection *= Speed; if (Input.GetButton("Jump")) { _animator.SetBool("is_in_air", true); _moveDirection.y = JumpSpeed; } else { _animator.SetBool("is_in_air", false); _animator.SetBool("run", move.magnitude > 0); } } _moveDirection.y -= Gravity * Time.deltaTime; timePlayMusicalSymbol += Time.deltaTime; if (Input.GetMouseButton(1)) { if (timePlayMusicalSymbol > 1f) { var adjustedPosition = musicalSymbolsTransform.position; adjustedPosition.x = transform.position.x; adjustedPosition.z = transform.position.z; musicalSymbolsTransform.position = adjustedPosition; musicalSymbolsTransform.forward = transform.forward; var adjustedRotation = transform.eulerAngles; adjustedRotation.x = 0f; adjustedRotation.z = 0f; musicalSymbolsTransform.transform.eulerAngles = adjustedRotation; _animator.SetTrigger("Play"); MusicalWooshsPool.PlaySfxOnPosition(transform.position); musicalSymbolsPS.Play(); timePlayMusicalSymbol = 0.0f; } } _characterController.Move(_moveDirection * Time.deltaTime); } }