Answer the question
In order to leave comments, you need to log in
How to fix error in Unity (c#) when getting "Animator" component?
There is an object with animation "FadeOn" and an animator on the object where there is a parameter "IsFadingOn" of type Boolean.
In the script, I'm trying to assign the "Animator" component to the "anim" variable, and then, using the StartLoadingScreen() function; start animation on button click in Canvas.
When saving a script, Unity gives this error: "The contextual keyword 'var' may only appear within a local variable declaration or in script code". I can't figure out why :| .
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Loading_Screen : MonoBehaviour
{
var anim = GetComponent<Animator>();
void StartLoadingScreen(){
anim.SetBool("IsFadingOn", true);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question