[GodotDL C# D4]
新增内容:
钻石/皇冠动画
Line.cs
using Godot;
public partial class Line : CharacterBody3D
{
[Export]
public Node Scene;
[Export]
public float Speed = 10f;
[Export]
public bool fly = false;
[Export]
public bool ground = false;
[Export]
public bool turn = false;
[Export]
public bool alive = true;
[Export]
public bool start = false;
[Export]
public MeshInstance3D tail;
[Export]
public CpuParticles3D FallEff;
[Export]
public CpuParticles3D DieEff;
[Export]
public AudioStreamPlayer song;
[Export]
public AudioStreamPlayer die;
[Export]
public MeshInstance3D LastTail;
/*Soon[Export]
public int DiamondCount = 0;
System.Action AddDiamond = () => {
DiamondCount++;
};
public override void _Ready()
{
Connect("process", Callable.From(AddDiamond));
}*/
public override void _PhysicsProcess(double delta)
{
Vector3 velocity = Velocity;
if (Input.IsActionJustPressed("ui_cancel"))
{
ReloadScene();
}
if (alive)
{
if (!IsOnFloor() && !fly)
{
ground = false;
velocity += GetGravity() * (float)delta;
}
if (IsOnFloor())
{
if (!ground)
{
FallEff.Emitting = true;
ground = true;
}
if (Input.IsActionJustPressed("ui_accept"))
{
//MakeTail();
if (!start)
{
start = true;
song.Play();
}
turn = !turn;
}
}
if (start)
{
if (turn)
{
//tail.Scale = new Vector3(tail.Scale.x, tail.Scale.y, -tail.Scale.z)
velocity.X = 0;
velocity.Z = Speed;
}
else
{
velocity.Z = 0;
velocity.X = Speed;
}
}
if (IsOnWall())
{
velocity = new Vector3(0, 0, 0);
alive = false;
die.Play();
DieEff.Emitting = true;
song.Stop();
}
}
Velocity = velocity;
MoveAndSlide();
}
public void ReloadScene()
{
SceneTree sceneTree = GetTree();
sceneTree.ReloadCurrentScene();
}
public void MakeTail()
{
Node Tail = tail.Duplicate();
tail.Position = Position;
Scene.AddChild(Tail);
}
}
Diamond.cs
using Godot;
public partial class Diamond : Area3D
{
[Export]
public CpuParticles3D effect;
[Export]
public MeshInstance3D mesh;
public override void _PhysicsProcess(double delta)
{
this.RotateY((float)(-delta));
}
private void _on_body_entered(Node3D body)
{
if (body is Line)
{
//EmitSignal("add_diamond");
mesh.Visible = false;
effect.Emitting = true;
}
}
}
Crown.cs
using Godot;
public partial class Crown : Area3D
{
[Export]
public CpuParticles3D effect;
[Export]
public MeshInstance3D mesh;
/*[Export]
public Node3D sprite;*/
public override void _PhysicsProcess(double delta)
{
this.RotateY((float)(-delta));
}
private void _on_body_entered(Node3D body)
{
if (body is Line)
{
//EmitSignal("add_crown");
mesh.Visible = false;
effect.Emitting = true;
}
}
}
弱弱问一句:在C#中怎么使用Connect,以实现注释中部分(2024.7.8停更)
目前找到的参考:
https://docs.godotengine.org/zh-cn/4.x/getting_started/step_by_step/signals.html
https://forum.godotengine.org/t/connecting-signals-and-c/53682/4
https://docs.godotengine.org/zh-cn/4.x/tutorials/scripting/c_sharp/c_sharp_signals.html
https://blog.csdn.net/weixin_44499065/article/details/133023475
本文来自博客园,作者:meny,转载请注明原文链接:https://www.cnblogs.com/meny233/p/18267341