我一直在努力在即将到来的游戏中找到一个简单的障碍。 它的眼光是,在一定时间之后射杀激光器。 我把激光器的时间推移到迄今为止的工作,但出于某种原因,更新激光器的最初位置,并告知激光器应当面对的方向,这不仅仅是一项挑战。
The relevant code is this:
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
probe = GetNode<Area2D>("FacingProbe");
lidSprite = GetNode<AnimatedSprite2D>("EvilEyeLid");
ballSprite = GetNode<AnimatedSprite2D>("EvilEyeBall");
ballSprite.Play("Idle");
switch (direction)
{
case 1: lidSprite.Rotation = 3.1416f; probe.Position = new Vector2(-20,0); break;
case 2: lidSprite.Rotation = 0; probe.Position = new Vector2(20,0); break;
case 3: lidSprite.Rotation = 4.712f; probe.Position = new Vector2(0,-20); break;
case 4: lidSprite.Rotation = 1.5708f; probe.Position = new Vector2(0,20); break;
}
}
// Called every frame. delta is the elapsed time since the previous frame.
public override void _Process(double delta)
{
if (pause == 0)
{
var packedLazer = GD.Load<PackedScene>("res://Entities/Lazer.tscn");
var lazer = packedLazer.Instantiate();
lazer.Position = probe.Position;
lazer.Direction = Direction;
AddChild(lazer);
}
animations();
}
For additional context:
probe is an Area2D located 20 units in front of the eye.
The game is tile based (square) and each tile is 20 units big
Direction is an integer variable on both the Eye and the laser it shoots
and the only code that s causing issues is the stuff inside of if (pause == 0)
Im 接收错误
Node does not contain a definition for Position and no accessible extension method Position accepting a first argument of type Node could be found
Node does not contain a definition for Direction and no accessible extension method Direction accepting a first argument of type Node could be found
The name Direction does not exist in the current context
for just a bit more context, here s both relevent properties under the inspector:
我确实不敢肯定我做错做什么,而且与“指示”等出口变量一起陷入困境,对我来说是完全新的,因此我大概会错过。