The problem is as follows, because when animator is activated, it is reset once and the parameters are lost
This problem persists, and the explanation given by the forum is to cache the parameters and reset them at the time of activation.
Http://answers.unity3d.com/questions/919995/parameters-and-states-of-animator-reset-on-objects.html
I modified the Forum script to add the script when I needed to close gameobject, and it was automatically deleted when I opened Gameobject again.
Can solve the parameter loss problem
//Modify from:http://answers.unity3d.com/questions/919995/parameters-and-states-of-animator-reset-on-objects.htmlusingUnityengine;usingSystem.Collections.Generic; Public classanimparamrecover:monobehaviour{classAnimcacheparam { PublicAnimatorcontrollerparametertype type; Public stringparamname; ObjectMdata; PublicAnimcacheparam (Animator Anim,stringparamname, Animatorcontrollerparametertype type) { This. Type =type; This. paramname =paramname; Switch(type) { CaseAnimatorcontrollerparametertype.int: This. Mdata = (int) Anim. Getinteger (paramname); Break; Caseanimatorcontrollerparametertype.float: This. Mdata = (float) Anim. GetFloat (paramname); Break; CaseAnimatorcontrollerparametertype.bool: This. Mdata = (BOOL) Anim. Getbool (paramname); Break; } } Public ObjectGetData () {returnMdata; }} Animator Manimator; List<AnimCacheParam>mparamscachelist; BOOLmisdisable; voidAwake () {Record (); } /// <summary> ///Recovery. /// </summary> voidonenable () {if(misdisable) {misdisable=false; } Else { return; } Recovery (); Destroy ( This); } voidondisable () {misdisable=true; } [ContextMenu ("Manual Record")] Public voidRecord () {mparamscachelist=NewList<animcacheparam>(); Manimator= getcomponent<animator>(); for(inti =0; i < mAnimator.parameters.Length; i++) { varp =Manimator.parameters[i]; varAnimparam =NewAnimcacheparam (Manimator, P.name, P.type); Mparamscachelist.add (Animparam); }} [ContextMenu ("Manual Recovery")] Public voidRecovery () {foreach(varParaminchmparamscachelist) { Switch(param.type) { CaseAnimatorControllerParameterType.Int:mAnimator.SetInteger (Param.paramname, (int) Param.getdata ()); Break; CaseAnimatorControllerParameterType.Float:mAnimator.SetFloat (Param.paramname, (float) Param.getdata ()); Break; CaseAnimatorControllerParameterType.Bool:mAnimator.SetBool (Param.paramname, (BOOL) Param.getdata ()); Break; }} mparamscachelist.clear (); }}
Animparamrecover
Parameter loss after animator component is turned off and turned on