Facebook
From Ratbagdoo, 2 Years ago, written in C.
Embed
Download Paste or View Raw
Hits: 146
  1. using UnityEngine.UI;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5.  
  6. public class PlayerMovement : MonoBehaviour
  7.  
  8. {
  9.     private Animator anim; // Reference to the animator component.
  10.      public Rigidbody2D rb;
  11.     private void start() {
  12.         rb = GetComponent<Rigidbody2D>();
  13.         Animator anim = GetComponent<Animator>();
  14.         anim.SetBool  ("Jump down", false);
  15.     }
  16.     private void Update()
  17.     {
  18.         if (Input.GetKey(KeyCode.RightArrow))
  19.         {
  20.            rb.velocity = new Vector2(2f ,0f); //this will move your RB to the right while you hold the right arrow
  21.         }
  22.  
  23.         if (Input.GetKey(KeyCode.LeftArrow))
  24.       {
  25.           rb.velocity = new Vector3(-2f ,0f); //this will move your RB to the left while you hold the right arrow
  26.        }
  27.      
  28.         if (Input.GetKey(KeyCode.UpArrow))
  29.       {
  30.           rb.velocity = new Vector4(0f ,2f); //this will move your RB up while you hold the right arrow
  31.        }
  32.         if (Input.GetKey(KeyCode.DownArrow))
  33.       {
  34.         anim.SetBool  ("Jump Down", true);
  35.        }  
  36.        
  37.       }
  38.     }