Youtube Answer – Facial Expression
This little post is an answer to the following question (Video: https://www.youtube.com/watch?v=LSrcQJHDUT4):
Here you can download a sample-project illustrating the concept: Test-Project (Unity 2018.2 required)
The general principle is not hard to understand. For our facial expressions, we use a texture which contains all possible eyes and mouths:
Then create a new material and assign the texture to it. Look at the offset-property and change its values. That’s actually the trick. By changing the offset you can shift the texture. So you have to set the offset values so that the texture is shifted to the correct place and displaying the eyes and mouth you want.
Of course, you can change the offset via script. Just change the
mainTextureOffset of the material.
Here’s the full script:
Attach the script to the mesh with the material and you can change the offset during play and edit mode (download the project and you can test it live):
Of course, our facial expression system is much more complex including a self-made editor to easily set up new facial expressions, but this is the essential concept behind it.