你好,我正在撰寫一個 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();
}
}
錯誤資訊
uj5u.com熱心網友回復:
這部分就在這里:
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>();
}
您不能將影片組件分配給 GameObject 型別。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/480214.html
上一篇:無法在VisualStudio2019中創建.NET5控制臺應用程式
下一篇:在C#中根據日期對子字串進行排序