ObjectColorFlash

ObjectColorFlash#

NAMESPACE:

UnityUtils.ScriptUtils.Objects

Apply a ObjectColorFlash script to an object and call its functions to flash it a certain color for a certain time. It works by changing the material of the specified object and changing the new materials color, then switching back to the default material after its done.

Warning

Do not modify a objects material while flashing, as it will interfere with the flashing. You can check if an object is flashing by calling IsFlashing().

Example Usage#

 using UnityEngine;
 using UnityUtils.ScriptUtils.Objects;

 public class ExampleScript : MonoBehaviour
 {
      public ObjectColorFlash object;
      public Material otherMat;

      void Start()
      {
         // Flashes the applied object white for 2 seconds.
         object.Flash(duration: 2);

         // Flashes the applied object blue for 2 seconds.
         object.Flash(Color.blue, 2);

         // Set the original material that is switched to after flashing
         object.SetOriginalMaterial(otherMat);

         // Check if the object is currently flashing
         bool isFlashing = object.IsFlashing();
      }
}

Warning

ObjectColorFlash only currently works with SpriteRenderers, but other compatibility is coming soon.

Functions#

UnityUtils.ScriptUtils.Objects.ObjectColorFlash : MonoBehaviour

Public Functions

bool IsFlashing()#

Determines whether a flashing operation is currently active.

Returns:

true if the object is flashing; otherwise, false.

void SetOriginalMaterial(Material mat)#

Sets the material that is switched back to after a flash is finished.

Parameters:

mat – Material to switch originalMaterial to

Coroutine Flash(Color color = default, float duration = default, Material flashMaterial = default)#

Flashes a SpriteRenderer.

Parameters:
  • color – Color to switch to. Default is the defaultFlashColor

  • duration – Time to switch the color for in seconds. Default is the defaultFlashDuration

  • flashMaterial – The material to use when flashing the color. Default is the defaultFlashDuration

Returns:

The coroutine started by the flash