test/Player/ClickToSpawn.cs
public sealed class ClickToSpawn : Component
{
[Property, InputAction]
public string InputAct { get; set; } = "Attack1";
[Property]
public GameObject Prefab { get; set; }
[Property]
public float Force { get; set; } = 1000f;
protected override void OnUpdate()
{
if ( Input.Pressed( InputAct ) )
{
var camRot = Scene.Camera.WorldRotation;
var obj = Prefab.Clone( new CloneConfig()
{
StartEnabled = true,
Transform = new Transform()
{
Position = Scene.Camera.WorldPosition + camRot.Forward * 50f,
Rotation = camRot
}
} );
if ( Force != 0 && obj.Components.TryGet<Rigidbody>( out var rb ) )
{
rb.ApplyImpulse( camRot.Forward * Force );
}
}
}
}