Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
-1
Question by fajarazizlaksono · Jan 03, 2013 at 12:40 PM · staticsettingput

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] );
 }
 */
 
Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MarkFinn · Jan 03, 2013 at 03:19 PM 0
Share

Ok... I looked, I got a headache. I went away, drank caffeine, came back, looked again and got another headache.

What.

avatar image TheDarkVoid · Jan 03, 2013 at 04:56 PM 0
Share

put this script on your player

avatar image AlucardJay · Jan 03, 2013 at 06:17 PM 0
Share

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

avatar image AlucardJay · Jan 03, 2013 at 06:21 PM 0
Share

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges