Unity C#-比较两个变量时遇到问题

时间:2018-11-28 09:59:22

标签: c# unity3d

这可能是一个愚蠢的问题... 我有两个变量,我将它们设置为连续数据(从arduino)不断变化的串行数据,只是在不同的时间。然后,我将它们彼此进行比较,以查看对象(IKTarget)是否应该向前(或向后)移动(统一)。

下面是我的代码:

void Start() {
   //Starting a new coroutine
   StartCoroutine(VariableSetter());
}

//Using that corouting
IEnumerator VariableSetter() {
    //Setting the first variable to the serialdata
    controllerfinger1_Angle = SerialDataDecoder.finger1_Angle;
    //Waiting 20ms
    yield return new WaitForSeconds(0.02f);
    //Setting the other variable to the serialdata
    newcontrollerfinger1_Angle = SerialDataDecoder.finger1_Angle;
}

void Update() {
    //Making the finger movement frame dependent
    amountToMove = speed * Time.deltaTime; */

    //If the finger angle is increasing
    if (newcontrollerfinger1_Angle > controllerfinger1_Angle)
    {
        //Move the IKTarget fowards (Closes the finger)
        IKTarget.Translate(Vector3.forward * amountToMove, Space.World);
    }
    //If the finger angle is decreasing
    if (newcontrollerfinger1_Angle < controllerfinger1_Angle)
    {
        //Move the IKTarget backwards (Opens up the finger)
        IKTarget.Translate(Vector3.back * amountToMove, Space.World);
    }
}

当我统一运行它时,IKTarget对象似乎不想移动。 我知道我的SerialData正确无误。

如果有人可以提供此问题的答案,将不胜感激。

谢谢, 以撒。

0 个答案:

没有答案
相关问题