我刚刚开始学习c#,并且对如何运作有非常基本的了解。我不断收到此代码中'player.HasGravity'行的错误代码'CS0154':
using GTA;
using System;
using System.Collections.Generic;
using GTA.Math;
using GTA.Native;
using System.Windows.Forms;
public class SuperJump : Script
{
public SuperJump()
{
Tick += OnTick;
KeyDown += OnKeyDown;
KeyUp += OnKeyUp;
Interval = 10;
}
void OnTick(object sender, EventArgs e)
{
}
void OnKeyDown(object sender, KeyEventArgs e)
{
}
void OnKeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Space)
{
Ped player = Game.Player.Character;
player.HasGravity
}
}
}
错误消息是:
属性或索引器'Entity.HasGravity'不能在此上下文中使用,因为它缺少get访问器'。
我看过一些有类似问题的帖子,但我仍然不明白问题是什么。
答案 0 :(得分:0)
检查你的角色类。 HasGravity属性很可能没有定义get方法,如此
class Character
{
private bool hasGravity;
public bool HasGravity
{
set { hasGravity = value; }
}
}
您需要执行以下操作来解决问题:
class Character
{
private bool hasGravity;
public bool HasGravity
{
set { hasGravity = value; }
get { return hasGravity; }
}
}