Visual Studio 以下括号教程和代码周围的“单位”不工作

gywdnpxw  于 2023-08-07  发布在  其他
关注(0)|答案(2)|浏览(93)

我正在学习Brackeys教程,该教程展示了如何创建回合制战斗https://www.youtube.com/watch?v=_1pz_ohupPs
我面临的问题是,我的代码不与某行代码一起工作,我想知道Unity是否可能在教程发布后改变了一些东西,因为它已经4岁了。
我的代码:

using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Unity.VisualScripting;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
using TMPro;

public enum BattleState { START, PLAYERTURN, ENEMYTURN, WON, LOST }

public class BattleSystem : MonoBehaviour
{
    public GameObject playerprefab;
    public GameObject enemyprefab;

    public Transform playerbattlestation;
    public Transform enemybattlestation;

    public TMP_Text dialogueText;

    public Unit playerUnit;
    public Unit enemyUnit;
    
    public BattleState state;

    void Start()
    {
        state = BattleState.START;
        SetupBattle();
    }

    private void SetupBattle()
    {
        GameObject playerGO = Instantiate(playerprefab, playerbattlestation);
        playerUnit = playerGO.GetComponent<Unit>();

        GameObject enemyGO = Instantiate(enemyprefab, enemybattlestation);
        enemyUnit = enemyGO.GetComponent<Unit>();

        dialogueText.text = enemyUnit.unitName + " Attacked!";  // Getting an error from this line
    }
}

字符串
在google上找不到任何关于这个的参考资料,我不知道Unit是做什么的,更不用说如何解决它了。
Error CS1061 'Unit' does not contain a definition for 'unitName' and no accessible extension method 'unitName' accepting a first argument of type 'Unit' could be found (are you missing a using directive or an assembly reference?) Assembly-CSharp C:\Users\rogue\Final Fantasy (Clone)\Assets\Scripts\BattleSystem.cs 46 Active

oxiaedzo

oxiaedzo1#

Unit是您之前创建的MonoBehaviour。使用以下命令检查该类的代码:

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

public class Unit : MonoBehaviour
{
    public string unitName;
    public int unitLevel;

    public int damage;

    public int maxHP;
    public int currentHP;

}

字符串

yjghlzjz

yjghlzjz2#

我想我已经弄明白了感谢你们,我试图引用一个脚本,这是不存在的,因为我已经命名的单元脚本的东西,但它并没有最初给予我一个错误,因为Unity.VisualScripting这导致它“工作”.

相关问题