Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 加速度计停止动画移动查询_C#_Animation_Unity3d_Accelerometer_Unity5 - Fatal编程技术网

C# 加速度计停止动画移动查询

C# 加速度计停止动画移动查询,c#,animation,unity3d,accelerometer,unity5,C#,Animation,Unity3d,Accelerometer,Unity5,我有一个名为AccelerometerMovement的脚本,负责播放器的加速计控制。播放器正在向左和向右移动,所以我只需要输入Input.acceleration.x 脚本如下: public class AccelerometerMovement : MonoBehaviour { private bool isandroid; private float AccelerometerStoreValue; private robotController theRo

我有一个名为AccelerometerMovement的脚本,负责播放器的加速计控制。播放器正在向左和向右移动,所以我只需要输入
Input.acceleration.x

脚本如下:

public class AccelerometerMovement : MonoBehaviour {
    private bool isandroid;

    private float AccelerometerStoreValue;

    private robotController theRobo;

    // Use this for initialization
    void Start () {
        theRobo = FindObjectOfType<robotController> ();


        #if UNITY_ANDROID
        isandroid=true;
        #else
        isandroid=false;
        #endif
    }

    // Update is called once per frame
    void Update () {
        if (isandroid) {
            //android specific code
            Accelerometer();


        } else {
            //any other platform specific code

        }
    }

    void Accelerometer(){
        AccelerometerStoreValue = Input.acceleration.x;
        if (AccelerometerStoreValue > 0.1f) {
            //right
            theRobo.moveRight();

        } else if (AccelerometerStoreValue < -0.1f) {
            //left
            theRobo.moveLeft();

        }
    }
}
现在,当我检查实际设备上的控件时,控件工作正常,但有一个问题

问题是,当播放器开始移动时,移动动画开始,但当它停止时,空闲动画(或停止动画)不会开始,,甚至当播放器移动动画仍在继续时。

现在我无法理解如何解决这个问题。

上面的
Stop()
函数处于休眠状态。我们需要附加一个条件来称之为:

 else if (AccelerometerStoreValue > 0.01f && AccelerometerStoreValue < 0.09f || AccelerometerStoreValue < -0.01f && AccelerometerStoreValue > -0.09f) {
            theRobo.stop ();
        }
else if(加速度计存储值>0.01f和加速度计存储值<0.09f | |加速度计存储值<-0.01f和加速度计存储值>-0.09f){
theRobo.stop();
}

这些值将照管设备,并将空闲动画设置为工作状态!将上述代码放在第二个之后,如果
accelerator()
功能中的

这是C#而不是Unityscript。请理解这一点。如果标签正确,您可能会得到更多帮助。你可以在谷歌上搜索Unity C#vs Unityscript,看看两者的区别。好的,我已经改变了!但是你知道@Programmer的解决方案吗?不知道,但是请编辑你的代码,添加代码的哪一部分应该停止并播放空闲的动画。检查你的动画和/或睡觉的身体,我解决了。把答案放进去
 else if (AccelerometerStoreValue > 0.01f && AccelerometerStoreValue < 0.09f || AccelerometerStoreValue < -0.01f && AccelerometerStoreValue > -0.09f) {
            theRobo.stop ();
        }