Unity AR 动画不会转换为游戏对象
Unity AR Animation doesn't convert to GameObject
你好,我正在编写 AR 应用程序,但我在 Unity 中遇到此类错误,所以我很困惑我需要更改什么。你能解释一下如何解决这个问题吗?
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
这部分就在这里:
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>();
}
应该是这样的:
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>();
}
不能将 Animation 组件分配给 GameObject 类型。
你好,我正在编写 AR 应用程序,但我在 Unity 中遇到此类错误,所以我很困惑我需要更改什么。你能解释一下如何解决这个问题吗?
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
这部分就在这里:
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>();
}
应该是这样的:
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>();
}
不能将 Animation 组件分配给 GameObject 类型。