我正在努力学习如何创建带有Unity的2D游戏,但是由于几个错误,我无法为CharacterMovement编译我的脚本。即使创建一个新的空脚本,编译器也说“未定义或导入预定义类型System.Void”,我无法在网上找到解决这个问题的方法。
这是空脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MyPlayerMovement : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
这就是我要编译的脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
public CharacterController2D controller;
public Animator animator;
public float runSpeed = 40f;
float horizontalMove = 0f;
bool jump = false;
bool crouch = false;
// Update is called once per frame
void Update () {
horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
animator.SetFloat("Speed", Mathf.Abs(horizontalMove));
if(horizontalMove == 0)
{
animator.SetBool("Jumping", false);
}
if (Input.GetButtonDown("Jump"))
{
jump = true;
animator.SetBool("Jumping", true);
}
if (Input.GetButtonDown("Crouch"))
{
crouch = true;
animator.SetBool("Crouching", true);
} else if (Input.GetButtonUp("Crouch"))
{
crouch = false;
animator.SetBool("Crouching", false);
}
}
void FixedUpdate ()
{
// Move our character
controller.Move(horizontalMove * Time.fixedDeltaTime, crouch, jump);
jump = false;
}
}
(在我的脚本中,我得到了大约60个类似的错误)
发布于 2019-09-09 11:05:13
将File->BuildSettings->playersettings-api兼容性级别中的选项更改为.Net 4X
发布于 2022-06-21 23:31:16
当我试图使用Microsoft.Toolkit.Uwp.Notification
安装Install-Package Microsoft.Toolkit.Uwp.Notifications -Version 7.1.2
时,就发生了这种情况。
一旦我这样做,我注意到一个新的配置文件被添加到我的解决方案资源管理器。我必须删除这个来修正错误。
发布于 2022-01-22 05:03:56
将来遇到这种情况的另一个可能的解决方案是:转到编辑->Preferences->外部工具->重新生成项目文件,以带回原来的CS项目& VS解决方案文件。
在尝试了其他常见的解决方案之后,这是唯一有效的选择,比如更改API兼容性、升级VS或删除项目obj文件夹。我认为这是因为我试图手动清除解决方案,并且在我试图删除一些包之后,联合最终破坏了一些包。因此,不幸的是,如果您尝试这样做,您将得到这个错误。
https://stackoverflow.com/questions/54789641
复制相似问题