Home > Software engineering >  Unity AR Animation doesn't convert to GameObject
Unity AR Animation doesn't convert to GameObject

Time:05-21

Hello i'm coding an AR application but i have this type of error in Unity so i'm confused what i'm need to change. May you explain me how to solve this problem?

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

public class WatchSelect : MonoBehaviour
{

    public GameObject watchModel1;
    public GameObject watchModel2;
    public GameObject watchModel3;

    public GameObject w1Window;
    public GameObject w2Window;
    public GameObject w3Window;

    
    Animation w1WindowAnimation;
    Animation w2WindowAnimation;
    Animation w3WindowAnimation;


    // Start is called before the first frame update
    void Start()
    {
       w1Window = w1Window.GetComponent<Animation>();
       w2Window = w1Window.GetComponent<Animation>();
       w3Window = w1Window.GetComponent<Animation>();
    }


    public void WatchOneButtonClicked()
    {
        // Showing watch 1 model on user's wrist
        watchModel1.SetActive(true);
        watchModel2.SetActive(false);
        watchModel3.SetActive(false);

        // Animating watch 1 window
        w1WindowAnimation["w1animation"].speed = 1;
        w1WindowAnimation.Play();
    }

    public void WatchTwoButtonClicked()
    {
        // Showing watch 2 model on user's wrist
        watchModel1.SetActive(false);
        watchModel2.SetActive(true);
        watchModel3.SetActive(false);

        // Animating watch 2 window
        w2WindowAnimation["w2animation"].speed = 1;
        w2WindowAnimation.Play();
    }

    public void WatchThreeButtonClicked()
    {
        // Showing watch 3 model on user's wrist
        watchModel1.SetActive(false);
        watchModel2.SetActive(false);
        watchModel3.SetActive(true);

        // Animating watch 3 window
        w3WindowAnimation["w3animation"].speed = 1;
        w3WindowAnimation.Play();
    }

}

error messages

CodePudding user response:

This part right here:

Animation w1WindowAnimation;
Animation w2WindowAnimation;
Animation w3WindowAnimation;


// Start is called before the first frame update
void Start()
{
   w1Window = w1Window.GetComponent<Animation>();
   w2Window = w1Window.GetComponent<Animation>();
   w3Window = w1Window.GetComponent<Animation>();
}

Should look like this:

Animation w1WindowAnimation;
Animation w2WindowAnimation;
Animation w3WindowAnimation;


// Start is called before the first frame update
void Start()
{
   w1WindowAnimation = w1Window.GetComponent<Animation>();
   w2WindowAnimation = w1Window.GetComponent<Animation>();
   w3WindowAnimation = w1Window.GetComponent<Animation>();
}

You cannot assign an Animation component to a GameObject type.

  • Related