[GodotDL C# D3]
书接上回 https://www.cnblogs.com/meny233/p/18264076
新增功能:
掉落/撞墙粒子
重载场景(报错,如图)
细节优化
Line.cs
using Godot;
using System;
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;
public MeshInstance3D LastTail;
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);
}
}
参考
Max模板
上回
本文来自博客园,作者:meny,转载请注明原文链接:https://www.cnblogs.com/meny233/p/18265084