example-grass/Eat Da Rich/Pig/PigCreator.cs

56 lines
1.1 KiB
C#
Raw Normal View History

2025-07-20 11:22:53 +00:00
using Godot;
using System.Collections;
using System.Collections.Generic;
using Godot.Collections;
namespace Rokojori
{
[GlobalClass,Tool]
public partial class PigCreator:Action
{
[Export]
public float radius = 100;
[Export]
public PackedScene packedScene;
[Export]
public Node container;
[Export]
public int maxPigs = 10;
2025-07-22 14:08:35 +00:00
[Export]
public float heightOffset = 0.6094f;
2025-07-20 11:22:53 +00:00
protected override void _OnTrigger()
{
2025-07-22 14:08:35 +00:00
2025-07-20 11:22:53 +00:00
if ( container.GetChildCount() >= maxPigs )
{
2025-07-22 14:08:35 +00:00
this.LogInfo( "Too many Pigs" );
2025-07-20 11:22:53 +00:00
return;
}
2025-07-22 14:08:35 +00:00
// this.LogInfo( "Creating Pigs" );
2025-07-20 11:22:53 +00:00
var n = packedScene.Instantiate() as Node3D;
if ( n == null )
{
this.LogInfo( n );
return;
}
container.AddChild( n );
2025-07-22 14:08:35 +00:00
var pig = n.Get<Pig>();
Trigger( pig.onSpawn );
var player = Unique<Player>.Get();
n.GlobalPosition = ( player.transformSource.GlobalPosition + GodotRandom.Get().InCube() * radius ).SetY( heightOffset );
2025-07-20 11:22:53 +00:00
}
}
}