Unity“无法加载关联的脚本"和"Win32Exception:系统找不到指定的文件". [英] Unity "The associated script can not be loaded" and "Win32Exception: The system cannot find the file specified"

查看:3024
本文介绍了Unity“无法加载关联的脚本"和"Win32Exception:系统找不到指定的文件".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我是Unity的新手,我一直在尝试用附加到角色的脚本来测试场景.但是,它总是说无法加载关联的脚本.请更正所有编译错误并分配有效的脚本."它还说文件的名称可能与代码中的名称不同,但不是,并且还说代码可能缺少MonoBehaviour脚本.它甚至不允许我将脚本附加到字符上,因为它找不到脚本类.

so I'm new to Unity and I've been trying to test the scene with the script attatched to a character. However, it keeps saying "The associated script cannot be loaded. Please fix any compile errors and assign a valid script." It also says that the name of the file could be different from the name in the code but it isnt, and also it says that the code could be missing MonoBehaviour Scripts. It wont even allow me to attach the script to characters because it cant find the script class.

我已经从互联网上复制并下载了角色移动代码,但是它们也不起作用.我也尝试过删除并重新制作CS文件,但这也没有用.除非我从添加组件"中添加字符,否则即使向字符添加空脚本也无法正常工作

I've copied and downloaded character movement codes from the internet but they didnt work either. I've also tried deleting and re-making the CS files but that didnt work either. Even adding empty scripts to characters didnt work unless i do it from "Add component"

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

public class Movement : MonoBehaviour
{
    SpriteRenderer sprite;
    Rigidbody2D rigid;

    // Start is called before the first frame update
    void Start()
    {
        sprite = GetComponent<SpriteRenderer>();
        rigid = GetComponent<Rigidbody2D>();
    }

    private void FixedUpdate()
    {
        if (Input.GetKey("d"))
            rigid.velocity = new Vector2(2, 0);
        else if (Input.GetKey("a"))
            rigid.velocity = new Vector2(-2, 0);
    }
}

如果有帮助,Unity中也会出现这些错误

There are also these errors in Unity if that helps

推荐答案

Unity显然无法处理编辑器目录名称中的撇号(单引号').您需要删除目录名中的撇号.进行更改后,Unity应该能够按预期构建脚本.

Unity apparently can't handle apostrophes (single-quote ') in the directory name of the editor. You need to get rid of the apostrophe in your directory name. Once you make that change, Unity should be able to build the scripts as intended.

这篇关于Unity“无法加载关联的脚本"和"Win32Exception:系统找不到指定的文件".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆