- Home /
How to make Screen player broken if look enemy ?
how to create player screen is broken if player see enemy?
This game might be like slenderman. I have a script for this but I do not know where I would put it -_- ?
where I can put the script and how to set it ???
sorry my question a bit strange.....
i need help !!
i get script from here : http://www.alucardj.net16.net/unityanswers/SlenderGuideV2-scene0.unitypackage
StaticScript :
#pragma strict
@script RequireComponent(MeshFilter, MeshRenderer)
var theAlpha : float = 0.0;
var theCamera : Camera;
var cameraTransform : Transform;
private var mesh : Mesh;
private var uv : Vector2[];
private var verts : Vector3[];
private var tris : int[];
private var normals : Vector3[];
public var distance : float = 1.0;
private var theMaterial : Material;
var theEnemy : EnemyScript;
function Start()
{
Startup();
// find and store a reference to the enemy script (to use health as alpha for texture)
if ( theEnemy == null )
{
theEnemy = GameObject.Find( "Enemy" ).GetComponent( EnemyScript );
}
}
function Update()
{
SetAlpha();
ScrollUVs();
}
function SetAlpha()
{
theAlpha = ( 100.0 - theEnemy.health ) * 0.01;
theMaterial.color = Color( theMaterial.color.r, theMaterial.color.g, theMaterial.color.b, theAlpha );
}
function ScrollUVs()
{
var scrollX : float = Random.Range( -0.5, 0.5 );
var scrollY : float = Random.Range( -0.5, 0.5 );
// UVs
for ( var i:int = 0; i < 4; i ++ )
{
uv[i] = new Vector2( uv[i].x + scrollX, uv[i].y + scrollY );
}
mesh.uv = uv;
}
// ----
function Startup()
{
if ( theCamera == null )
{
theCamera = Camera.main;
}
cameraTransform = theCamera.transform;
theMaterial = gameObject.renderer.material;
theMaterial.color = Color.white;
if ( !mesh )
{
GetComponent(MeshFilter).mesh = mesh = new Mesh();
mesh.name = "ScreenMesh";
}
Construct();
//DebugVerts();
}
function Construct()
{
mesh.Clear();
verts = new Vector3[4];
uv = new Vector2[4];
tris = new int[6];
normals = new Vector3[4];
// calculate verts based on camera FOV
var pos : Vector3 = cameraTransform.position - transform.position;
var halfFOV : float = ( theCamera.fieldOfView * 0.5 ) * Mathf.Deg2Rad;
var aspect : float = theCamera.aspect;
//Debug.Log( " Screen.width " + Screen.width + " : Screen.height " + Screen.height + " : aspect " + aspect );
var height : float = distance * Mathf.Tan( halfFOV );
var width : float = height * aspect;
//Debug.Log( " fieldOfView " + theCamera.fieldOfView + " : aspect " + aspect );
// UpperLeft
verts[0] = pos - (cameraTransform.right * width);
verts[0] += cameraTransform.up * height;
verts[0] += cameraTransform.forward * distance;
// UpperRight
verts[1] = pos + (cameraTransform.right * width);
verts[1] += cameraTransform.up * height;
verts[1] += cameraTransform.forward * distance;
// LowerLeft
verts[2] = pos - (cameraTransform.right * width);
verts[2] -= cameraTransform.up * height;
verts[2] += cameraTransform.forward * distance;
// LowerRight
verts[3] = pos + (cameraTransform.right * width);
verts[3] -= cameraTransform.up * height;
verts[3] += cameraTransform.forward * distance;
// UVs
uv[0] = new Vector2( 0.0, 1.0 );
uv[1] = new Vector2( 1.0, 1.0 );
uv[2] = new Vector2( 0.0, 0.0 );
uv[3] = new Vector2( 1.0, 0.0 );
// Triangles
tris[0] = 0;
tris[1] = 1;
tris[2] = 2;
tris[3] = 2;
tris[4] = 1;
tris[5] = 3;
// Normals
normals[0] = -Vector3.forward;
normals[1] = -Vector3.forward;
normals[2] = -Vector3.forward;
normals[3] = -Vector3.forward;
// assign mesh
mesh.vertices = verts;
mesh.uv = uv;
mesh.triangles = tris;
mesh.normals = normals;
mesh.RecalculateBounds();
mesh.RecalculateNormals();
}
/*
function DebugVerts()
{
// Debug Positions
Debug.Log( " UL " + verts[0] + " : UR " + verts[1] );
Debug.Log( " LL " + verts[2] + " : LR " + verts[3] );
}
*/
Ok... I looked, I got a headache. I went away, drank caffeine, came back, looked again and got another headache.
What.
Wow .... when did you get this? I removed that package ages ago as it just created a flood of questions. Anyway , what this script does is create a quad (a simple mesh) for the whole camera view, then a variable changes the alpha of the material, all while the UVs are randomly updated. This creates a full-screen static effect.
1/ create an empty gameObject
2/ attach this script
3/ make the object a child of the camera
4/ set the transform and rotation to zero for all axis
5/ customize the script for your needs ....
eg : this was written to check the variable health on another script, that value being between 1 and 100. Then a normalized value is calculated in SetAlpha()
change the following functions :
function Start()
{
Startup();
}
function SetAlpha()
{
the$$anonymous$$aterial.color = Color( the$$anonymous$$aterial.color.r, the$$anonymous$$aterial.color.g, the$$anonymous$$aterial.color.b, theAlpha );
}
now the script works simply by plugging into and changing the variable theAlpha to a value between 0 and 1
TO future readers who are lucky enough to stumble across this, the answer to this question has already been given in a comment by me (AlucardJ) to Peanut97 in the comments where all questions related to this guide should be posted : http://answers.unity3d.com/questions/296068/how-to-make-a-slender-man-follow-character-script.html
$$anonymous$$y comment :
Yeah I wrote that script for this, but it pretty cool so might use it for other full-screen effects (blood splats, rain). I asked a question on how to use an unlit shader (so the whole effect is bright, not just where the flashlight hits it), the answer and shader can be found here : http://answers.unity3d.com/questions/345917/correct-unlit-shader-to-use-when-fading-a-material.html Edit : the shader is now in the V2 package =]
This was my last response : http://answers.unity3d.com/questions/351575/need-help-with-showing-slender-static.html
Answer by AlucardJay · Jan 03, 2013 at 06:33 PM
1/ create an empty gameObject
2/ attach this script
3/ make the object a child of the camera
4/ set the transform and rotation to zero for all axis
5/ customize the script for your needs ....
eg : change the following functions :
function Start()
{
Startup();
}
function SetAlpha()
{
theMaterial.color = Color( theMaterial.color.r, theMaterial.color.g, theMaterial.color.b, theAlpha );
}
now the script works simply by plugging into and changing the variable theAlpha to a value between 0 and 1
Your answer
Follow this Question
Related Questions
If there is only 1 instance of a class, should it be Static? - C# 2 Answers
Accessing another var on another script 1 Answer
Global Varible Problem 2 Answers
Problems with variables across scripts 0 Answers
When passing a value it becomes null 0 Answers