找不到我的代码有任何问题,但是,我有八条错误消息.四个CS1519,两个CS1001,CS1022和CS8124


//using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine;
public interface IPlayer
{
Rigidbody2D MyRigidbody { get; set; }
float Speed { get; }
}
[DebuggerDisplay("{{{nameof(DebuggerDisplay)}(),nq}}")]
public class Player : MonoBehaviour, IPlayer
{
private Rigidbody2D _myRigidbody;
private float speed;
public float Speed => speed;
private void SetSpeed() => speed = value;
// Start is called before the first frame update
void Start()=>
_myRigidbody = this.GetComponent<Rigidbody2D>();
private string DebuggerDisplay => ToString();
public Rigidbody2D MyRigidbody { get => _myRigidbody; set => _myRigidbody = value; }

// Update is called once per frame
void Update()
{
float move = Input.GetAxis("Horizontal");
_myRigidbody.velocity = new Vector2(move = speed, _myRigidbody.velocity.y);
}
// Start is called before the first frame update
_myRigidbody = this.GetComponent<Rigidbody2D>();**Whole line seems to have errors Three CS1519 errors and One CS8124 error**

// Update is called once per frame
{
float move = Input.GetAxis("Horizontal");
_myRigidbody.velocity = new Vector2(move = speed, _myRigidbody.velocity.y);
**Whole line has errors↑ Two CS1001 errors and One CS1519 error**   
}** error CS1022: Type or namespace definition, or end-of-file expected**
}

该代码是为我正在进行的课程项目编写的,应该使用左右箭头键在水平位置移动游戏对象。当谈到c#时,我只是一个初学者,在网上其他地方找不到任何有用的东西。任何帮助都将不胜感激。

它们都是编译器错误,因为代码混乱。这就像有人复制粘贴了你的代码,然后把它搞砸了。甚至评论都是一样的。

using System.Collections;//Namespace was commented out.
using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine;
public interface IPlayer
{
Rigidbody2D MyRigidbody { get; set; }
float Speed { get; }
}
[DebuggerDisplay("{{{nameof(DebuggerDisplay)}(),nq}}")]
public class Player : MonoBehaviour, IPlayer
{
private Rigidbody2D _myRigidbody;
private float speed;
public float Speed => speed;
private void SetSpeed() => speed = value;
// Start is called before the first frame update
void Start()=>
_myRigidbody = this.GetComponent<Rigidbody2D>();
private string DebuggerDisplay => ToString();
public Rigidbody2D MyRigidbody { get => _myRigidbody; set => _myRigidbody = value; }

// Update is called once per frame
void Update()
{
float move = Input.GetAxis("Horizontal");
_myRigidbody.velocity = new Vector2(move = speed, _myRigidbody.velocity.y);
}
// This particular line may need to be called elsewhere but, it's a 
// value assignment without a codeblock. Place this inside the update
// method or comment it out. 
// (Probably delete it since you are assigning this in the delegate named start.)
//   _myRigidbody = this.GetComponent<Rigidbody2D>();
// The other code block wasn't named or demarked with anything and it 
// was literally a carbon copy of your Update method.
}

最新更新