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

56 lines
1.1 KiB
C#

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;
[Export]
public float heightOffset = 0.6094f;
protected override void _OnTrigger()
{
if ( container.GetChildCount() >= maxPigs )
{
this.LogInfo( "Too many Pigs" );
return;
}
// this.LogInfo( "Creating Pigs" );
var n = packedScene.Instantiate() as Node3D;
if ( n == null )
{
this.LogInfo( n );
return;
}
container.AddChild( n );
var pig = n.Get<Pig>();
Trigger( pig.onSpawn );
var player = Unique<Player>.Get();
n.GlobalPosition = ( player.transformSource.GlobalPosition + GodotRandom.Get().InCube() * radius ).SetY( heightOffset );
}
}
}