Created
June 19, 2023 00:09
-
-
Save NanoDano/524956f2db5c6c89fe531b1eaee4a89f to your computer and use it in GitHub Desktop.
Play animation on keypress in Unity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class PlayAnimationOnKey : MonoBehaviour | |
{ | |
public Animation animationToPlay; | |
// Start is called before the first frame update | |
void Start() | |
{ | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
if (Input.GetKeyDown(KeyCode.Space)) | |
{ | |
animationToPlay.Play(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment