【问题标题】:I can't add component because "there is error" but I can't see it. How can I solve the problem?我无法添加组件,因为“有错误”但我看不到它。我该如何解决这个问题?
【发布时间】:2019-04-13 12:31:42
【问题描述】:

我在做一个游戏。一部分离线,另一部分使用网络。 我已经创建了我的脚本副本以脱机工作。我的脚本(monobehaviour)没有错误,但是当我尝试在我的 GameObject unity 上添加组件时,我会报错:

"无法添加脚本组件'RocketOffline',因为脚本类 找不到。确保没有编译错误,并且 文件名和类名匹配”

我的脚本和名称匹配没有任何错误 (RocketOffline.cs VS RocketOffline : MonoBehaviour)

我尝试重新导入我的脚本,重新导入所有资产并将我的所有代码复制到另一个脚本中,但似乎没有任何效果...

我在其他脚本上也有同样的问题,但我只会展示其中一个

public class RocketOffline : MonoBehaviour
{
    public GameObject Explosion;

    private Vector3 Direction;
    private Color Couleur;
    private float vitesse;
    private float multiplieur;
    int NumPlayer;


    void Explose(Vector3 position)
    {
        ExplosionOffline instance = Instantiate(Explosion, position, new Quaternion()).GetComponent<ExplosionOffline>();
        instance.NumPlayer = NumPlayer;
        foreach (var SmokeEffect in GetComponentsInChildren<ParticleSystem>())
        {
            SmokeEffect.transform.parent = null;
            Destroy(SmokeEffect.gameObject, SmokeEffect.startLifetime);
            SmokeEffect.Stop();
        }
        Destroy(gameObject);
    }

    private void OnCollisionEnter(Collision collision)
    {
        Explose(transform.position);
    }

    private void OnTriggerExit(Collider other)
    {
        GetComponent<Collider>().isTrigger = false;

    }

    public void SetSpeed(Vector3 _Direction, float _Vitesse, JoueurOffline _Player)
    {
        Direction = _Direction;
        vitesse = _Vitesse;
        Couleur = _Player.Couleur;
        NumPlayer = _Player.NumPlayer;
    }

    void Start()
    {
        Rigidbody rigid = GetComponent<Rigidbody>();
        transform.eulerAngles = Vector3.forward * Mathf.Atan2(-Direction.x, Direction.y) * Mathf.Rad2Deg;
        rigid.velocity = Direction * vitesse;
        multiplieur = transform.localScale.y / 10;
        GetComponentInChildren<MeshRenderer>().material.color = Couleur;
    }

    void Update()
    {
        GetComponent<Rigidbody>().velocity = transform.up * vitesse;
        RaycastHit info;
        Physics.Raycast(new Ray(transform.position, GetComponent<Rigidbody>().velocity * Time.deltaTime), out info);
        if (info.distance < vitesse * Time.deltaTime * multiplieur/* && info.collider.gameObject != gameObject && info.collider.gameObject != player.gameObject*/)
        {
            Explose(info.point);
        }
    }
}

我只想在我的GameObject 上添加我的脚本,就像通常在 Unity 上一样。 但总是有同样的错误。 我的脚本在其他项目上进行了测试并且运行良好。我认为这可能是统一的内部错误。

【问题讨论】:

  • 与您所说的其他项目和这个项目有什么不同?
  • 遗憾的是,什么都没有。但是当我创建这个脚本时,原来的名字是 Rocket_Offline。但是我们不能在类名中使用下划线,所以我把它改成了 RocketOffline。既然有错误。但是这两个脚本是一样的……

标签: c# unity3d


【解决方案1】:

是的,这可能是 Unity 的一个错误。 如果您使用的是新的 2019 测试版,那么只需提交错误报告 :)

【讨论】:

  • 我正在使用 unity 2018 ^^ 但是是的,我会发送错误报告。那么你认为没有解决方案,我应该创建另一个项目吗?谢谢
  • 是的,试着用另一个名字复制另一个类中的代码
【解决方案2】:

我认为您可以尝试重新导入脚本或 rm 项目的库文件夹。

【讨论】:

  • 谢谢,但我已经尝试过 :( 我不得不创建另一个项目。最后我复制粘贴了我的脚本,现在一切正常但是谢谢大家的回复
猜你喜欢
  • 2023-01-07
  • 1970-01-01
  • 2013-11-23
  • 2021-07-01
  • 1970-01-01
  • 2021-09-19
  • 2020-09-10
  • 2021-10-02
  • 1970-01-01
相关资源
最近更新 更多