[英]Sprite does not contain a definition for sprite and no accessible extension method 'sprite' accepting a first argument of type 'Sprite' could be found
so im using unity and i got this error:所以我使用统一,我得到了这个错误:
https://i.stack.imgur.com/UukR5.png https://i.stack.imgur.com/UukR5.png
and the code is:代码是:
using System.Collections;使用 System.Collections;
using System.Collections.Generic;使用 System.Collections.Generic;
using UnityEngine;使用 UnityEngine;
using UnityEngine.UI;使用 UnityEngine.UI;
public class CharacterManager : MonoBehaviour { public CharacterDatabase characterDB;公共类 CharacterManager : MonoBehaviour { 公共 CharacterDatabase characterDB;
public Text nameText;
public Sprite artworkSprite;
private int selectedOption = 0;
// Start is called before the first frame update
void Start()
{
UpdateCharacter(selectedOption);
}
public void NextOption()
{
selectedOption++;
if(selectedOption >= characterDB.CharacterCount)
{
selectedOption = 0;
}
UpdateCharacter(selectedOption);
}
public void BackOption()
{
selectedOption--;
if(selectedOption < 0)
{
selectedOption = characterDB.CharacterCount - 1;
}
UpdateCharacter(selectedOption);
}
private void UpdateCharacter(int selectedOption)
{
Character character = characterDB.GetCharacter(selectedOption);
artworkSprite.sprite = character.characterSprite; <-- where the error is
nameText.text = character.characterName;
}
} }
please help asap thanks请尽快帮助谢谢
you can use 2 ways to set sprite您可以使用 2 种方式来设置精灵
artworkSprite = character.characterSprite;
or或者
public Image artworkImage;
...
artworkImage.sprite = character.characterSprite;
I hope it will work on your project.我希望它适用于您的项目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.