- Home /
Enable Camera Image Effect on Button Down
Hi there, i'm new to Unity 3D and i have a small question to ask. I'm currently working on a 3rd Person Adventure and so far everything is going great. I'm not experienced in Javascript so please bear with me.
The code i'm requesting is that when i hit the any of the Vertical (Up/Down arrow) keys (in which the player moves forward), the image effect, Fisheye, attached to the camera enables while the player is holding the up/down arrow key. Once the player let's go of the arrow keys, the image effect is disabled. May i please have the code to this? Thank you :)
Answer by Statement · Dec 15, 2010 at 02:41 PM
FisheyeController.js
private var effect : Fisheye; effect = GetComponent("Fisheye");
function Update () { var keysWS = Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.S); effect.enabled = keysWS; }
However I think you want to apply a smooth transition on the bend instead.
SmoothFisheyeController.js
private var effect : Fisheye; effect = GetComponent("Fisheye");
var strengthX : float = 0.05f; var strengthY : float = 0.05f; var speed : float = 0.05f;
function Update () { var keysWS = Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.S); var targetX = keysWS ? strengthX : 0; var targetY = keysWS ? strengthY : 0; var move = Time.deltaTime * speed; effect.strengthX = Mathf.MoveTowards(effect.strengthX, targetX, move); effect.strengthY = Mathf.MoveTowards(effect.strengthY, targetY, move); }
Your answer
![](https://koobas.hobune.stream/wayback/20220613091129im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Using The Same Input Key To Switch Between Two Camera Views 1 Answer
Cinemachine Input Provider requires InputActionReference. Any workarounds? 0 Answers
How to switch between four characters when a button is pressed? 1 Answer
ScreenToWorldPoint fixed height 1 Answer
ipad splitscreen display and on screen joystick and button ui 0 Answers