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

43 lines
836 B
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;
protected override void _OnTrigger()
{
if ( container.GetChildCount() >= maxPigs )
{
return;
}
var n = packedScene.Instantiate() as Node3D;
if ( n == null )
{
this.LogInfo( n );
return;
}
container.AddChild( n );
n.GlobalPosition = GodotRandom.Get().InCube() * new Vector3( 1, 0, 1 ) * radius + new Vector3( 0, 0.5f, 0 );
}
}
}