/*
     * Handle entered enermy
     */
    private PandaMove OnEnermyEnter(GameObject gameObject)
    {
        PandaMove pandaMove = null;

        // Lock target if target was null or target changed
        if (targetLocked == null || targetLocked != gameObject)
        {
            if (targetLocked != null)
            {
                // Unlock
                PandaMove lastPandaMove = targetLocked.GetComponent <PandaMove>();
                if (lastPandaMove != null)
                {
                    lastPandaMove.Unlock();
                }
            }

            targetLocked = gameObject;
            pandaMove    = gameObject.GetComponent <PandaMove>();
            if (pandaMove != null)
            {
                if (midiPlayer)
                {
                    midiPlayer.AddNote(new SingleNote(baseNote + pandaMove.index, 0.5f));
                }

                pandaMove.Lock();
            }
        }

        return(pandaMove);
    }
    /*
     * Keyboard/Mouse Control detector
     */
    private void Control()
    {
        // Teleport
        if (Input.GetKeyUp(KeyCode.T))
        {
            if (teleport)
            {
                teleport.SwitchPosition();
            }
        }

        // Get raycast object
        GameObject gameObject = GetRaycastedObject(currentCamera);

        if (gameObject != null)
        {
            if (gameObject.CompareTag("Enermy"))
            {
                OnEnermyEnter(gameObject);
            }
            else if (targetLocked != null && targetLocked.CompareTag("Enermy"))
            {
                PandaMove lastPandaMove = targetLocked.GetComponent <PandaMove>();
                if (lastPandaMove != null)
                {
                    lastPandaMove.Unlock();
                }

                targetLocked = null;
            }

            if (Input.GetMouseButtonUp(0) && gameObject.CompareTag("MagicBall"))
            {
                OnBallPlayed(gameObject);
            }

            if (Input.GetMouseButton(1) && gameObject.CompareTag("MagicBall"))
            {
                OnBallGet(gameObject, currentCamera);
            }
        }
        else if (targetLocked != null && targetLocked.CompareTag("Enermy"))
        {
            PandaMove lastPandaMove = targetLocked.GetComponent <PandaMove>();
            if (lastPandaMove != null)
            {
                lastPandaMove.Unlock();
            }

            targetLocked = null;
        }

        // Launch projectile
        if (Input.GetMouseButtonUp(0))
        {
            LaunchProjectile(currentCamera);
        }

        // Middle Click, show balls
        if (Input.GetMouseButtonUp(2))
        {
            if (magicBallGenerator)
            {
                if (isBallShowed)
                {
                    magicBallGenerator.HideMagicBall();
                    isBallShowed = false;
                }
                else
                {
                    magicBallGenerator.ShowMagicBall();
                    isBallShowed = true;
                }
            }
        }
    }
    /*
     * VR Control listener
     */
    private void VRControl()
    {
        // Teleport - Right Hand Grip pressed
        if (ViveInput.GetPressUp(HandRole.RightHand, ControllerButton.Grip))
        {
            if (teleport)
            {
                teleport.SwitchPosition();
            }
        }

        // Get raycast object of MainCamera
        GameObject gameObject = GetRaycastedObject(currentCamera);

        if (gameObject != null)
        {
            if (gameObject.CompareTag("Enermy"))
            {
                OnEnermyEnter(gameObject);
            }
            else if (targetLocked != null && targetLocked.CompareTag("Enermy"))
            {
                PandaMove lastPandaMove = targetLocked.GetComponent <PandaMove>();
                if (lastPandaMove != null)
                {
                    lastPandaMove.Unlock();
                }

                targetLocked = null;
            }
        }
        else if (targetLocked != null && targetLocked.CompareTag("Enermy"))
        {
            PandaMove lastPandaMove = targetLocked.GetComponent <PandaMove>();
            if (lastPandaMove != null)
            {
                lastPandaMove.Unlock();
            }

            targetLocked = null;
        }

        // Left hand play note of ball
        gameObject = GetRaycastedObject(leftManette);
        if (gameObject != null)
        {
            Animator leftAnimator = leftManette.GetComponentInChildren <Animator>();

            if (leftAnimator != null)
            {
                // Lighten magic effects
                // We can also use setActive of sub components, but this is for practicing animator
                leftAnimator.SetBool("IsHalt", false);
                leftAnimator.SetBool("IsAttracting", true);
            }

            if (ViveInput.GetPadPressVector(HandRole.LeftHand) != Vector2.zero && gameObject.CompareTag("MagicBall"))
            {
                OnBallPlayed(gameObject);

                ViveInput.TriggerHapticPulse(HandRole.LeftHand, 500);
            }

            if (ViveInput.GetPress(HandRole.LeftHand, ControllerButton.Trigger) && gameObject.CompareTag("MagicBall"))
            {
                if (OnBallGet(gameObject, leftManette) != null)
                {
                    Animator rightAnimator = rightManette.GetComponentInChildren <Animator>();
                    if (rightAnimator != null)
                    {
                        // Light magic effects
                        rightAnimator.SetBool("IsLaunched", false);
                        rightAnimator.SetBool("IsCharged", true);
                    }
                }
            }
        }
        else
        {
            // Need test
            Animator leftAnimator = leftManette.GetComponentInChildren <Animator>();
            if (leftAnimator != null)
            {
                // Close magic effects
                leftAnimator.SetBool("IsHalt", true);
                leftAnimator.SetBool("IsAttracting", false);
            }
        }

        // Launch projectile
        if (ViveInput.GetPressDown(HandRole.RightHand, ControllerButton.Trigger))
        {
            LaunchProjectile(rightManette);

            Animator rightAnimator = rightManette.GetComponentInChildren <Animator>();
            if (rightAnimator != null)
            {
                // Close magic effects
                rightAnimator.SetBool("IsLaunched", true);
                rightAnimator.SetBool("IsCharged", false);
            }

            ViveInput.TriggerHapticPulse(HandRole.RightHand, 500);
        }

        // Right touch pad, play current note
        if (ViveInput.GetPadPressVector(HandRole.RightHand) != Vector2.zero)
        {
            if (chargedIndex != -1)
            {
                if (midiPlayer)
                {
                    midiPlayer.AddNote(new SingleNote(baseNote + chargedIndex, 0.5f));
                }
                ViveInput.TriggerHapticPulse(HandRole.RightHand, 500);
            }
        }

        // Left grib, show balls
        if (ViveInput.GetPressUp(HandRole.LeftHand, ControllerButton.Grip))
        {
            if (magicBallGenerator)
            {
                if (isBallShowed)
                {
                    magicBallGenerator.HideMagicBall();
                    isBallShowed = false;
                }
                else
                {
                    magicBallGenerator.ShowMagicBall();
                    isBallShowed = true;
                }
            }
        }
    }