animator Unity бросание кости
Здравствуйте делаю игру 2д при выполнении кода на анимацию плюс рандом ( myAnim.Play(playAnim + rang) ) пишет Ошибка CS0103 Имя "playAnim" не существует в текущем контексте.
rang = Random.Range(1, 6);
myAnim.Play(playAnim + rang);
а если например так то есть как мне сделать рандомную анимацию
rang = Random.Range(1, 6);
myAnim.Play(playAnim6);
то все норм помогите пожалуйста
playAnim 1-6 это анимация выпадения где цифра указывает на какуя грань выпала кость
Ответы (2 шт):
Автор решения: Dima
→ Ссылка
что делать при такой ошибки в кансоли когда ты пытаешся включить анимации этим кодом
{
Animator myAnim;
public string kubi1;
public string kubi2;
public string kubi3;
public string kubi4;
public string kubi5;
public string kubi6;
public bool firstAnimInclouded = true;
public int rang;
//public AudioClip saundAnim1;
//public AudioClip saundAnim2;
void Start()
{
myAnim = GetComponent <Animator> ();
print(("kubi",Random.Range(1, 7)));
}
public void Tap()
{
if (firstAnimInclouded)
{
rang = Random.Range(1, 7);
myAnim.SetInteger("kubi",Random.Range(1, 7));
firstAnimInclouded = false;
}
else
{
rang = Random.Range(1, 6);
myAnim.SetInteger("kubi", Random.Range(1, 7));
firstAnimInclouded = true;
}
}
}
Parameter 'kubi' does not exist.
0x00007ff6ecc5930d (Unity) StackWalker::GetCurrentCallstack
0x00007ff6ecc5ffe9 (Unity) StackWalker::ShowCallstack
0x00007ff6edbcd613 (Unity) GetStacktrace
0x00007ff6ee26223d (Unity) DebugStringToFile
0x00007ff6ecf4233f (Unity) Animator::WarningStringIfLoggingActive
0x00007ff6ecf414a9 (Unity) Animator::ValidateParameterString
0x00007ff6ebf2a61f (Unity) Animator_CUSTOM_SetIntegerString
0x0000027c718d510f (Mono JIT Code) (wrapper managed-to-native) UnityEngine.Animator:SetIntegerString (UnityEngine.Animator,string,int)
0x0000027c718d5043 (Mono JIT Code) UnityEngine.Animator:SetInteger (string,int)
0x0000027c718d4ff3 (Mono JIT Code) [game.cs:44] game:Tap ()
0x0000027c6c1d98b9 (Mono JIT Code) UnityEngine.Events.InvokableCall:Invoke ()
0x0000027c6c1d92ab (Mono JIT Code) UnityEngine.Events.UnityEvent:Invoke ()
0x0000027c718d4153 (Mono JIT Code) [Button.cs:71] UnityEngine.UI.Button:Press ()
0x0000027c718d40b3 (Mono JIT Code) [Button.cs:115] UnityEngine.UI.Button:OnPointerClick (UnityEngine.EventSystems.PointerEventData)
0x0000027c718d4059 (Mono JIT Code) [ExecuteEvents.cs:58] UnityEngine.EventSystems.ExecuteEvents:Execute (UnityEngine.EventSystems.IPointerClickHandler,UnityEngine.EventSystems.BaseEventData)
0x0000027c7188bce2 (Mono JIT Code) [ExecuteEvents.cs:272] UnityEngine.EventSystems.ExecuteEvents:Execute<T_REF> (UnityEngine.GameObject,UnityEngine.EventSystems.BaseEventData,UnityEngine.EventSystems.ExecuteEvents/EventFunction`1<T_REF>)
0x0000027c718d3d1b (Mono JIT Code) [StandaloneInputModule.cs:192] UnityEngine.EventSystems.StandaloneInputModule:ReleaseMouse (UnityEngine.EventSystems.PointerEventData,UnityEngine.GameObject)
0x0000027d18f93fc3 (Mono JIT Code) [StandaloneInputModule.cs:642] UnityEngine.EventSystems.StandaloneInputModule:ProcessMousePress (UnityEngine.EventSystems.PointerInputModule/MouseButtonEventData)
0x0000027d18f8d54b (Mono JIT Code) [StandaloneInputModule.cs:547] UnityEngine.EventSystems.StandaloneInputModule:ProcessMouseEvent (int)
0x0000027d18f8d3eb (Mono JIT Code) [StandaloneInputModule.cs:527] UnityEngine.EventSystems.StandaloneInputModule:ProcessMouseEvent ()
0x0000027d18f8cd03 (Mono JIT Code) [StandaloneInputModule.cs:282] UnityEngine.EventSystems.StandaloneInputModule:Process ()
0x0000027c6c315c7f (Mono JIT Code) [EventSystem.cs:504] UnityEngine.EventSystems.EventSystem:Update ()
0x0000027d18d34cc8 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
0x00007ffd5cede4b4 (mono-2.0-bdwgc) [mini-runtime.c:3445] mono_jit_runtime_invoke
0x00007ffd5ce1e764 (mono-2.0-bdwgc) [object.c:3066] do_runtime_invoke
0x00007ffd5ce1e8fc (mono-2.0-bdwgc) [object.c:3113] mono_runtime_invoke
0x00007ff6ecb7dac4 (Unity) scripting_method_invoke
0x00007ff6ecb78644 (Unity) ScriptingInvocation::Invoke
0x00007ff6ecb462b4 (Unity) MonoBehaviour::CallMethodIfAvailable
0x00007ff6ecb463bc (Unity) MonoBehaviour::CallUpdateMethod
0x00007ff6ec63dbc8 (Unity) BaseBehaviourManager::CommonUpdate<BehaviourManager>
0x00007ff6ec6451aa (Unity) BehaviourManager::Update
0x00007ff6ec855cad (Unity) `InitPlayerLoopCallbacks'::`2'::UpdateScriptRunBehaviourUpdateRegistrator::Forward
0x00007ff6ec83c89c (Unity) ExecutePlayerLoop
0x00007ff6ec83c973 (Unity) ExecutePlayerLoop
0x00007ff6ec8425d9 (Unity) PlayerLoop
0x00007ff6ed7899d9 (Unity) PlayerLoopController::UpdateScene
0x00007ff6ed787bdf (Unity) Application::TickTimer
0x00007ff6edbd37aa (Unity) MainMessageLoop
0x00007ff6edbd805b (Unity) WinMain
0x00007ff6eef5b42e (Unity) __scrt_common_main_seh
0x00007ffdb18d54e0 (KERNEL32) BaseThreadInitThunk
0x00007ffdb382485b (ntdll) RtlUserThreadStart
Автор решения: Andrew_STOP_RU_AGRESSION_IN_UA
→ Ссылка
необходимо создать массив из анимаций:
Animation[] animations = new Animation[] {anim1, anim2,anim3,anim4,anim5,anim6 };
и доставать случайную анимацию из этого масива:
var randNum = Random.Range(1, animations.length);
myAnim.Play(animations[randNum]);