Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Animation script turnes animatio on & off?

Discussion in '2D' started by Deleted User, May 15, 2020.

  1. Deleted User

    Deleted User

    Guest

    Hi I'm quite new to unity and i want to find/make a script that starts a jumping animation while jumping and stops when the player hits the ground, I've made a basic script with the help of unity docs but errors pop up everywhere. Could someone improve my code?
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Jump_Check_Anim : MonoBehaviour
    6. {
    7.     // Start is called before the first frame update
    8.     void Start()
    9.     {
    10.        
    11.     }
    12.      private Animation anim;
    13.     // Update is called once per frame
    14.     // Checks If jumped, then playes jump animation
    15.     void Update()
    16.     {
    17.         if (IsGrounded && Input.GetKeyDown(KeyCode.Space)){
    18.          anim.Play("PlayerJumpAnim");
    19.         }
    20.     }
    21. }
     
  2. Deleted User

    Deleted User

    Guest

    Actually im an idiot and didnt know what the animator window was