예제 #1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonDown("BallToggle"))
        {
            bounce = !bounce;
        }

        if (oldbounce != bounce)
        {
            ShowBall(bounce);

            if (!bounce && arduino != null)
            {
                arduino.EnableHapticFeedback(false);
            }
            oldbounce = bounce;
        }

        if (oldIntensity != intensity && arduino != null)
        {
            arduino.AdjustHapticFeedback(intensity);
            oldIntensity = intensity;
        }

        if (bounce)
        {
            if (anchor != null)
            {
                startPosition = anchor.position + anchorOffset;
            }

            float ballHeight = Mathf.Abs(Mathf.Sin(frequency * Time.time));
            offset             = Vector3.zero;
            offset.y           = amplitude * ballHeight;
            transform.position = startPosition + offset;

            if (arduino != null)
            {
                //arduino.AdjustHapticFeedback(intensity);
                if (ballHeight < skinThickness)
                {
                    if (!hitting)
                    {
                        hitting = true;
                        arduino.EnableHapticFeedback(true);
                    }
                    //arduino.AdjustHapticFeedback(intensity - ballHeight);
                }
                else
                {
                    if (hitting)
                    {
                        hitting = false;
                        arduino.EnableHapticFeedback(false);
                    }
                    //arduino.AdjustHapticFeedback(0);
                }
            }
        }
    }