Type of Namespace Could not be found - Animation related
I'm looking to use a single animation to animate multiple objects Error is underlined at with error code : The Type of namespace HO1could not be found, which is clearly alocated and linked in-game.
[SerializeField]
public Image Heart2;
[SerializeField]
public Animation HO1;
void Start()
{
Heart2.GetComponent<HO1>().Play();
ResetQuestion();
}
I'm sure Unity is smarter than this, and i'm just missing out on something. Thanks guys, i couldn't find a matching issue anywhere else.
Answer by Pengocat · Dec 17, 2016 at 02:36 PM
Heart2.GetComponent<HO1>().Play();
Should be...
Heart2.GetComponent<Animation>().Play();
if you want to play the animation on the GameObject Hearth2 reference
or...
GetComponent<Animation>().Play();
If you want to play HO1 from this GameObject
Forgot to mention i'm a beginner, and i might ask some stupid questions ... Your response seems to return no errors when i replaced Heart2.GetComponent().Play(); with Heart2.GetComponent().Play(); But now i don't understand how to link the "Animation" to the component, and now what would be the point of na$$anonymous$$g a animation if i won't be using it anyway. For instance i want to play Animation"HO1" won the image Heart2 How would that look like in code ?
You are right that na$$anonymous$$g it without using it is redundant. You should assign it ins$$anonymous$$d like this if you want to reuse the method many times like when pressing the Spacebar.
Animation anim;
void Start()
{
anim = GetComponent<Animation>();
}
void Update()
{
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space))
{
anim.Play();
}
}
Just keep in $$anonymous$$d that the Animation component is considered Legacy and you should learn about using the Animator ins$$anonymous$$d.
Answer by Swegfan · Dec 17, 2016 at 05:40 PM
[SerializeField]
public GameObject Heart2;
[SerializeField]
public AnimationClip HO1;
void Start()
{
ResetQuestion();
Animation anim = Heart2.AddComponent<Animation>();
anim.clip = HO1;
anim.Play();
}
found the answer myself, but the problem gets a bit more complicated ... i'd like to animate the object the animation is attached to ... any quick solution for this ?