# Light Script

**URL:** https://discussions.unity.com/t/light-script/431679
**Category:** Scripting
**Tags:** Scripting
**Created:** [December 21, 2010, 3:40pm UTC](https://discussions.unity.com/t/light-script/431679 "2010-12-21T15:40:40Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![anon\_5878642](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@anon\_5878642](https://discussions.unity.com/u/anon_5878642)
#### Post date: [December 21, 2010, 3:40pm UTC](https://discussions.unity.com/t/light-script/431679/1 "2010-12-21T15:40:40Z")

</div>

I need to create this script, please.  
When you press W so as to perform the animation “dopredu.anim”  
And if I let the press so that the animation stopped.

---

<div class="post-metadata">

### Author: ![anon\_14570844](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@anon\_14570844](https://discussions.unity.com/u/anon_14570844)
#### Post date: [December 21, 2010, 4:42pm UTC](https://discussions.unity.com/t/light-script/431679/2 "2010-12-21T16:42:23Z")

</div>

Can’t see how what you ask for is related to a light?  
Are you wanting the animation to only play whilst the W key is pressed?

You could do a check if the W key is pressed to play the animation.  
And when the key is released to stop as two distinct events.

If you need to readup more on [animation scripting](http://unity3d.com/support/documentation/Manual/Animation%20Scripting.html) then there is a good introduction in the documentation section

You will need to have an [animation](http://unity3d.com/support/documentation/ScriptReference/Animation.html) component added to your gameobject. In the update of a new script applied to the object

function [Update](http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.Update.html) () {  
if ([Input.GetKeyDown](http://unity3d.com/support/documentation/ScriptReference/Input.GetKeyDown.html) (“w”))  
[animation.Play](http://unity3d.com/support/documentation/ScriptReference/Animation.Play.html)(“dopredu”, PlayMode.StopAll);  
if ([Input.GetKeyUp](http://unity3d.com/support/documentation/ScriptReference/Input.GetKeyUp.html)(“w”))  
[animation.Stop](http://unity3d.com/support/documentation/ScriptReference/Animation.Stop.html)(“dopredu”);  
}
