- 已关闭。**此问题为not reproducible or was caused by typos。当前不接受答案。
这个问题是由打字错误或无法再重现的问题引起的。虽然类似的问题在这里可能是on-topic,但这个问题的解决方式不太可能帮助未来的读者。
2天前关闭。
Improve this question
我试图在Unity中制作一个游戏,我已经制作了动作,但现在我想制作命令游戏模式,但每次我尝试使用对象"left. Execute"时,我都会在标题中得到错误-"Assets\Character. cs(23,13):错误CS0201:只有赋值、调用、递增、递减、等待和新建对象表达式可以用作语句"这是我的代码。
Commandclass.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Commandclass
{
public interface Execute
{
void Execute();
}
Character.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Character : MonoBehaviour
{
float speed = 3f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
Vector3 position = transform.position;
if (Input.GetKey(KeyCode.LeftArrow))
{
//position.x += speed * Time.deltaTime;
Lmovements left = new Lmovements(position);
left.Execute;
}
if (Input.GetKey(KeyCode.RightArrow))
{
position.x -= speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.UpArrow))
{
position.z -= speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.DownArrow))
{
position.z += speed * Time.deltaTime;
}
transform.position = position;
}
}
Lmovements.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Lmovements : Commandclass.Execute
{
Vector3 cdirection;
float speed = 3f;
public Lmovements(Vector3 direction)
{
cdirection = direction;
}
public void Execute()
{
cdirection.x += speed * Time.deltaTime;
}
}
1条答案
按热度按时间5cg8jx4n1#
我怀疑问题出在
left.Execute;
线上。Execute
看起来像一个方法,但您并没有调用该方法,只是以一种既非方法又非方法的方式引用它:要调用它,必须使用括号:
left.Execute();