- Add FloatingTextManager prefab to scene.
- Generate floating text by calling:
FloatingTextManager.instance.CreateFloatingText(...)
if (Input.GetKeyDown(KeyCode.F))
{
FloatingText instance = FloatingTextManager.instance.CreateFloatingText(transform, "Hello world!", 0, 0);
instance.SetParent(transform);
instance.SetScalingMode(ScalingMode.scaleWithDistance, 2.0f);
}
This will spawn a FloatingText at the given transform
. You can also customize some of the details using certain FloatingText
methods (see below for more details).
I suggest duplicating and renaming the existing FloatingText_Default prefab, then tweaking the relevant components in its child object.
After you're satisfied, add your new prefab to the FloatingTextManager's floatingTextPrefabs
array in the inspector.
You can also create new animations for the prefab using the Animation window. Make sure the prefab is in scene and you have its child with the Animator componenent selected.
After you're satisfied, add your new animation to the FloatingTextManager's animations
array in the inspector.
Call these from anywhere if you want to spawn a new FloatingText.
Transform t
- Prefab will be spawned at this position.string textValue
- Text that will appear.int prefabIndex
- Prefab that will be spawned based on floatingTextPrefabs[].int animIndex
- Animation that will play based on animations[].
Call these methods on the spawned instance returned by CreateFloatingText(...)
.
ScalingMode newMode
- Can either be:constantScale
orscaleWithDistance
.float newScale
- Pretty self explanatory!
(By default, these values will be based on settings in FloatingTextManager)
Transform t
- Transform that the floating text will become a child of.
(By default, it will be a child of the FloatingTextManager)
- Martin Glaude (@quill18) - SimplePool.cs Utilizes object pooling instead of instantiating for better optimization.