This project provides a custom Unity shader that can make objects appear as if they're encased in ice. The ice effect can be animated, allowing objects to transition smoothly between their normal appearance and the frozen state.
The shader uses albedo and normal maps as a base but includes additional properties to adjust the ice effect. It takes into consideration properties like Fresnel reflection, transparency, specular highlights and reflectivity to provide a more realistic ice appearance.
The accompanying FreezeObject.cs script is responsible for gradually changing an object's appearance to a frozen state. It adjusts the _FrozenAmount property of the shader over time to create the transition.
- Import shader into project
- Create a new Material (Right click in Project panel -> Create -> Material).
- In the Inspector, set the Shader of this material to the new ice shader (should be under Custom -> IceShader).
- Adjust the shader properties as needed. For instance, you can change the
_FrozenAmount,_IceColor,_Transparency, and_Glossinessto suit your needs.
// Simply attach this component to any object that contains a renderer to begin freezing it.
enemy.gameObject.AddComponent<FreezeObject>();
// Example logic for "Freezing" enemy
enemy.gameObject.GetComponent<EnemyAI>().enabled = false;
enemy.gameObject.GetComponent<Animation>().speed = 0;
AudioSource.PlayClipAtPoint(freezeSound, enemy.transform.position, 0.5f);When you play the scene, you should see the GameObject gradually transition to a frozen state over timeToFreeze seconds.
It is very important to note, that you should never add the FreezeObject script to an object more than once. A flag of some kind is useful:
if(!enemy.isFrozen)
{
enemy.gameObject.AddComponent<FreezeObject>();
enemy.isFrozen=true;
}It is also VERY important to note that shader MUST be installed into a /Resources/ folder in order for the FreezeObject script to function. If it is not, the shader will be pink.