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.

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

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);
   
}

Last updated