Example #1
0
 // Update is called once per frame
 void Update()
 {
     if (COMport.isConnected())
     {
         transform.GetChild(0).GetComponent <Text>().text = "Winkel:" + COMport.getServoAngle(ID);
     }
     else
     if (Direktion == 'X' || Direktion == 'x')
     {
         transform.GetChild(0).GetComponent <Text>().text = "Winkel:" + (Main.Gelenk[ID].GetComponent <Gelenk_Parameter>().transform.eulerAngles.x).ToString();
     }
     else
     if (Direktion == 'Y' || Direktion == 'y')
     {
         transform.GetChild(0).GetComponent <Text>().text = "Winkel:" + (Main.Gelenk[ID].GetComponent <Gelenk_Parameter>().transform.eulerAngles.y).ToString();
     }
     else
     if (Direktion == 'Z' || Direktion == 'z')
     {
         transform.GetChild(0).GetComponent <Text>().text = "Winkel:" + (Main.Gelenk[ID].GetComponent <Gelenk_Parameter>().transform.eulerAngles.z).ToString();
     }
 }
    // Update is called once per frame
    void Update()
    {
        if (!COMport.isConnected())
        {
            if (Direktion == 'X' || Direktion == 'x')
            {
                RotateVector.x = RotateSpeed;
            }
            if (Direktion == 'Y' || Direktion == 'y')
            {
                RotateVector.y = RotateSpeed;
            }
            if (Direktion == 'Z' || Direktion == 'z')
            {
                RotateVector.z = RotateSpeed;
            }
            transform.Rotate(RotateVector);
            RotateAngles = transform.localEulerAngles;
        }
        else
        {
            if (Direktion == 'X' || Direktion == 'x')
            {
                RotateAngles.x = (float)Angle;
            }
            if (Direktion == 'Y' || Direktion == 'y')
            {
                RotateAngles.y = (float)Angle;
            }
            if (Direktion == 'Z' || Direktion == 'z')
            {
                RotateAngles.z = (float)Angle;
            }
            double schritt = (COMport.getServoAngle(ID) - OldAngle) / 12;//Interval;

            Angle += schritt;

            if (schritt > 0)
            {
                if (Angle >= COMport.getServoAngle(ID))
                {
                    Angle = COMport.getServoAngle(ID);
                }
            }


            if (schritt < 0)
            {
                if (Angle <= COMport.getServoAngle(ID))
                {
                    Angle = COMport.getServoAngle(ID);
                }
            }



            //if (Math.Round(Angle, 4) == Math.Round(COMport.getServoAngle(ID)))
            //    Angle = COMport.getServoAngle(ID);

            if (TempAngle != COMport.getServoAngle(ID))
            {
                Interval        = IntervalCounter;
                IntervalCounter = 0;
                OldAngle        = TempAngle;
                TempAngle       = COMport.getServoAngle(ID);
            }
            IntervalCounter++;
            transform.localEulerAngles = RotateAngles;
        }
    }