尝试在Unity中使用带网格的字符串时出现错误:
无法将类型“UnityEngine.Mesh”隐式转换为“UnityEngine.Mesh []”
错误代码:错误CS0029:无法将类型“UnityEngine.Mesh”隐式转换为“UnityEngine.Mesh []”
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
public class HatSwitch : MonoBehaviour
{
[SerializeField] private MeshFilter modelYouWantToChange;
[SerializeField] private Mesh[] modelYouWantToUse;
private int currentModel;
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
modelYouWantToChange.mesh = modelYouWantToUse[currentModel];
currentModel++;
if (currentModel >= modelYouWantToUse.Length)
{
currentModel = 0;
}
}
}
public void ChangeMeshButton()
{
modelYouWantToChange.mesh = modelYouWantToUse[currentModel];
currentModel++;
if (currentModel >= modelYouWantToUse.Length)
{
currentModel = 0;
}
}
public void ChangeMeshButtonBack()
{
modelYouWantToChange.mesh = modelYouWantToUse[currentModel];
currentModel--;
if (currentModel >= modelYouWantToUse.Length)
{
currentModel = 0;
}
}
}
尝试为游戏创建换肤器:
Seen here
1条答案
按热度按时间ergxz8rk1#
我不知道是哪一行导致了异常,也不清楚
modelYouWantToUse
数组是如何填充的,而且我根本不了解Unity,但我会这样做: