Git Product home page Git Product logo

unity-easy-damage-numbers's Introduction

Unity Floating Text System

How to use

  • Add FloatingTextManager prefab to scene.
  • Generate floating text by calling: FloatingTextManager.instance.CreateFloatingText(...)

Example usage

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).


Custom FloatingTexts

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.

Custom Animations

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.


FloatingTextManager Methods

Call these from anywhere if you want to spawn a new FloatingText.

FloatingText CreateFloatingText(Transform t, string textValue, int prefabIndex, int animIndex)
  • 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[].

FloatingText Methods

Call these methods on the spawned instance returned by CreateFloatingText(...).

void SetScalingMode(ScalingMode newMode, float newScale)
  • ScalingMode newMode - Can either be: constantScale or scaleWithDistance.
  • float newScale - Pretty self explanatory!

(By default, these values will be based on settings in FloatingTextManager)

void SetParent(Transform t)
  • Transform t - Transform that the floating text will become a child of.

(By default, it will be a child of the FloatingTextManager)


Credits

  • Martin Glaude (@quill18) - SimplePool.cs Utilizes object pooling instead of instantiating for better optimization.

unity-easy-damage-numbers's People

Contributors

bryjch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

r2d2m

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.