By the looks of your code you’re never actually referencing the attached Animaton on your component. Try assigning anim it’s component in the Start method, like this:
public class PlayAnimation : MonoBehaviour { public AnimationClip walk; Animation anim; void Start() { anim = GetComponent<Animation>(); } void Update () { if (Input.GetKeyDown(KeyCode.W)) { anim.clip = walk; anim.Play(); } } }
Related Posts:
- How to find child of a GameObject or the script attached to child GameObject via script
- Getting mouse position in unity
- How to make the script wait/sleep in a simple way in unity
- Unity OnTriggerEnter2D not registering
- C# 2D platformer movement code
- OnCollisionEnter() not working in Unity3D
- Are there any B-tree programs or sites that show visually how a B-tree works
- Unity cannot convert from ‘string’ to ‘int’
- Can’t add script component because the script class cannot be found?
- Why should I use SerializeField?
- OnTriggerEnter not working at Unity3D
- How to jump in Unity 3d?
- Unity3d no Monobehaviour scripts in the file, or their names don’t match the file name
- Unity3d restart current scene
- How to move 2D Object with WASD in Unity
- The Object you want to instantiate is null. Unity 3D
- Unity 2d jumping script
- OnCollisionEnter2D not being executed?
- Unity “The associated script can not be loaded” and “Win32Exception: The system cannot find the file specified”
- Unity – Gameobject look at mouse
- How to add a delay in a C# unity script
- Error when Building Project: Error building Player because scripts have compile errors in the editor
- Unity3D. Trying to send command for object without authority
- Expression denotes a `type’, where a `variable’, `value’ or `method group’ was expected UNITY3D
- How to add .gif Animation in unity Scene ? Does Unity support Animated GIFS?
- Auto scrolling with CSS
- How to pass data (and references) between scenes in Unity
- Rotate object in Unity 3D
- OnCollisionEnter is not called in unity
- Unity 5.2.2 changing Visual Studio back to MonoDevelop
- “A namespace cannot directly contain members such as fields or methods”
- Unity – How to stop Play Mode in case of infinite loop?
- Unity Scripts edited in Visual studio don’t provide autocomplete
- Is there a keyboard shortcut to maximize the Game window in Unity in Play Mode?
- How to connect to database from Unity
- .Net 4.8 Support for Windows 10 ends in 26 days?
- How can I convert String to Int?
- Process cannot access the file because it is being used by another proess
- How to convert JSON to XML or XML to JSON?
- Virustotal Trapmine suspicious.low.ml.score
- TypeScript foreach return [duplicate]
- Convert int to string?
- How to Sort a List
by a property in the object - The page was not displayed because the request entity is too large on IIS
- Unable to resolve service for type while attempting to activate
- Multiple Inheritance in C#
- Wait one second in running program
- Deserialize JSON with C#
- “Error while trying to run project: Unable to start program”. Can run program only once. Then VS needs restart
- What is WebResource.axd?
- What is clr.dll on .Net framework and what does it do?
- Associating enums with strings in C#
- Proper Linq where clauses
- Unity UI button not reacting to clicks or hovering
- Validation failed for one or more entities. See ‘EntityValidationErrors’ property for more details
- How to resolve this System.IO.FileNotFoundException
- What is the best way to implement a “timer”?
- SmtpException: Unable to read data from the transport connection: net_io_connectionclosed
- How can I get the application’s path in a .NET console application?
- How do I encode and decode a base64 string?
- How to keep console window open
- Tree data structure in C#
- What is 0x10 in decimal?
- Visual Studio: The Operation could not be completed. The parameter is incorrect
- Member ‘
‘ cannot be accessed with an instance reference - Sequence contains no matching element
- when do you need .ascx files and how would you use them?
- Pass Method as Parameter using C#
- How to open a new form from another form
- C# – How to convert string to char?
- How to properly exit a C# application?
- The entity type
is not part of the model for the current context - Recommendation for C# Matrix Library
- Deep cloning objects
- Regular expression “^[a-zA-Z]” or “[^a-zA-Z]”
- .NET graph library around?
- How to transparent Unity3D custom shader?
- Input string was not in a correct format
- Verify a method call using Moq
- XmlSerializer – There was an error reflecting type
- Run Command Prompt Commands
- Cannot implicitly convert type ‘System.Collections.Generic.List< >‘ to ‘System.Collections.Generic.IList< >‘
- How can I wait for a thread to finish with .NET?
- How do I exit a WPF application programmatically?
- What is a method group in C#?
- The name ‘ViewBag’ does not exist in the current context – Visual Studio 2015
- How to create a new object instance from a Type
- Background of MainCamera (Unity C#)
- does not implement interface member
- Differences between SFTP and “FTP over SSH”
- When should I use a List vs a LinkedList
- Remove punctuation from string with Regex
- Go To Definition: “Cannot navigate to the symbol under the caret.”
- Why am I getting an Exception with the message “Invalid setup on a non-virtual (overridable in VB) member…”?
- IF Statement multiple conditions, same statement
- What is the easiest way to handle associative array in c#?
- What does the M stand for in C# Decimal literal notation?
- Iif equivalent in C#
- Convert an array to string
- is inaccessible due to its protection level