当我将动画速度变为零时,它可以正常工作,但当将其恢复为1时,它在UnityScript中不起作用

时间:2017-03-27 23:36:31

标签: c# unity3d

因此,当我创建一个设置脚本,使用复选框打开和关闭动画时,当我关闭动画关闭时,它工作正常,但当我再次单击该复选框时,动画不会再次关闭。 这是我的剧本:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class AnimationSettings : MonoBehaviour {

public Toggle TheCheckbox; 

public Animator[] TheAnimators;

[SerializeField] int thelength;

public static int animationsetting;

void Awake(){

    thelength = TheAnimators.Length;
    DontDestroyOnLoad (gameObject.transform);
}

public void SaveSettings(){

    PlayerPrefs.SetInt ("Animations", animationsetting);
    PlayerPrefs.Save ();
}



public void SetAnimationSettings(){

    bool onoroff = PlayerPrefs.GetInt ("Animations") == 1;

    if (onoroff)
        PlayerPrefs.SetInt ("Animations", 1);
    if (!onoroff) 
        PlayerPrefs.SetInt("Animations", 0);

    PlayerPrefs.Save ();

    if (PlayerPrefs.GetInt ("Animations") == 0) {




        for(int i=0; i<=thelength-1; i++){

            Animator animforthisround = TheAnimators[i];
            animforthisround.speed = 0;

        }

    } else if(PlayerPrefs.GetInt ("Animations") == 1){



        for(int i=0; i<=thelength-1; i++){

            Animator animforthisround = TheAnimators[i];
            animforthisround.speed = 1;

        }

    }

}

public void Update(){


}

}

如果你能提供帮助,那就太好了,因为我很难过。我到处寻找,没有任何帮助。

0 个答案:

没有答案