Skip to content

Controller

Assets/FORGE3D/DamageFX/Scripts/DamageFX.cs

In order to control the Damage FX Shader, an instance of the script should be present on each Damage FX Object. The script component handles the data processing for impact spots and fades the heat values over time.

Damage FX inspector with Decay Tick Rate 0.25 and Decay Per Tick 2.

Use DamageFX.Hit() method of the script to add new impacts to the surface of the mesh as shown below:

Damage FX Hit method adding an impact point, cycling the counter, and updating material arrays.

Here is the simple code snippet that will add the damage point to the Damage FX Object under the mouse cursor on left mouse click:

public float HitRadius = 0.1f;
public float Dirt = 1f;
public float Burn = 1f;
public float Heat = 1f;
public float Clip = 0.7f;
private RaycastHit _hitInfo;
private void Update()
{
if (!Input.GetMouseButtonDown(0)) return;
var screenRay = Camera.main.ScreenPointToRay(Input.mousePosition);
if (!Physics.Raycast(screenRay, out _hitInfo, Mathf.Infinity)) return;
var dfx = _hitInfo.collider.GetComponent<DamageFX>();
if (dfx != null) dfx.Hit(dfx.transform.InverseTransformPoint(_hitInfo.point), HitRadius, Dirt, Burn, Heat, Clip);
}