- Home /
How to make a plane with a texture flicker, as if it was animated?
I am trying to make a death scene in my game similar to the one in the Slender games. When you die, you would see the monster's face and static would flicker all over the screen.
I have the face ready in front of the Main Camera and I have a plane placed in front of the face, closer to the camera. I added the static texture, but my question is:
Is there a script that makes the texture's offset randomize all the time, making it look as if the static is moving?
I have this happening when I see the monster within the actual game, from this helpful guide, but I want to make this death scene and I am totally in the dark at the moment...
Ummm, you already have the script for that. $$anonymous$$y static offset function in the PlayerHealth script.
function Offset$$anonymous$$ainTexture()
{
var rndXoffset : float = Random.value;
var rndYoffset : float = Random.value;
staticRenderer.material.mainTextureOffset = Vector2( rndXoffset, rndYoffset );
}
http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$aterial-mainTextureOffset.html
Hey alucardj! I got the script for the player health, but I am looking for the static texture to just flicker all by itself. Without the need of a player or health of any kind.
I have a scene called "SceneLose" (from your old guide) and I just have a black skybox for the entire background, slender man's face right up on the camera, and I just have a plane with the static texture.
Would I just create a new script and reference it to your static offset function in the script?
Answer by AlucardJay · May 13, 2013 at 03:48 AM
This is where I'm giving you the key but I want you to open the door yourself.
There is a gameObject, with a renderer that has a material :
renderer.material
You want to offset the texture on that material : http://docs.unity3d.com/Documentation/ScriptReference/Material-mainTextureOffset.html
renderer.material.mainTextureOffset = Vector2( valueX, valueY);
Then you want to randomize the offset between 0 and 1 : http://docs.unity3d.com/Documentation/ScriptReference/Random-value.html
var valueX : float = Random.value;
var valueY : float = Random.value;
Put it all together in a script on it's own, then attach it to the static object :
function Update()
{
var valueX : float = Random.value;
var valueY : float = Random.value;
renderer.material.mainTextureOffset = Vector2( valueX, valueY );
}
exactly the same as the OffsetMainTexture() function
Lol, again, sorry for my lack of knowledge on all of this. I have actually gotten a lot more familiarized with Unity in just a few weeks, a lot thanks to you alucardj. I have opened the door. xD
I also created my main menu, the credits page, and many more scenes thanks to your old videos and I have given you many thanks in the credits scene.