Material Setting

Put shader inside a material, and then it becomes a material for the indicator.

image.png

Options

Thickness: Thickness of the outline. FillAmount: Fill amount of the indicator.

Texture

MainTex: Texture of the outline. GradientTex: Texture of the fill.

image.png

Options

Thickness: Thickness of the outline. FillAmount: Fill amount of the indicator. Radius: 0~1, Radius of the Circle. InnerRadius: 0~1, InnerRadius of the Circle. Angle: 0~360, A measure of how many degrees of a circle to use.

Texture

MainTex: Texture of the outline. GradientTex: Texture of the fill.

Gradient Image Setting

image.png

Set Gradient texture image like this. Wrap Mode must not be Repeat.

Demo

If demo doesn’t work and you using Unity 6.0 or above, you have to check the settings.

image.png

In the script named “IndicatorMaker”, it uses the old input system (Input Manager). So you have to check the Project Settings. Edit > Project Settings > Player > Other Settings > Configuration > Active Input Handling Set to Input Manager (Old) or Both.

Script

image.png

image.png

Prefabs have own script. It is just for demo. You can use your own script if you want it.


Demo is using these scripts.

This is Spawning of BoxIndicator.

// Instantiate and Decleration of BoxIndicator
BoxIndicator boxIndicator = Instantiate(
boxIndicatorPrefab, 
hit.point + (Vector3.up * 0.1f), 
Quaternion.identity)
.GetComponent<BoxIndicator>();

// Initialize te BoxIndicator
boxIndicator.Initialize(new Vector3(xSize, 1, ySize), duration);

This is Initializing of BoxIndicator.

// Instance the Material to prevent it from transforming the source.
private void Awake()
{
    if (mesh != null && mesh.sharedMaterial != null)
    {
        material = new Material(mesh.sharedMaterial);
        mesh.material = material;
    }
}

// The process of initializing to use Indicator.
public void Initialize(Vector3 size, float time)
{
    decay = 0;
    lifeTime = time;
    transform.localScale = size;

    material = new Material(mesh.sharedMaterial);
    mesh.material = material;

    if (material != null)
    {
        material.SetFloat(FillAmountProp, 0f);
    }
}

// If using Object Pooling System, this is for it.
private void PrepareForDespawn()
{
    decay = 0f;
    if (material != null)
    {
        material.SetFloat(FillAmountProp, 0f);
    }
}

// After spawn, Updates value for animation and lifetime.
private void Update()
{
    if (lifeTime <= 0)
        return;

    decay += Time.deltaTime;

    material.SetFloat(FillAmountProp, decay / lifeTime);
    if (decay >= lifeTime)
    {
        PrepareForDespawn();
        Destroy(gameObject); // Despawn here, If you using an object pooling system.
    }
}