Advertisement
Atomic_Violetta

Hero not moving

Mar 13th, 2024
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.72 KB | Gaming | 0 0
  1. using UnityEngine;
  2.  
  3. public class HeroScript : MonoBehaviour
  4. {
  5.     // Set my Speed. If There is no speed, you can't move.
  6.     [SerializeField] private float memberSpeed = 10.0f;
  7.  
  8.     // I still don't know.
  9.     private SpriteRenderer memberSpriteRenderer = null;
  10.  
  11.     // I STILL don't know. Rigid Body.
  12.     private Rigidbody2D memberRigidBody = null; // I don't know, I'll tell you later.
  13.  
  14.     // Start is called before the first frame update
  15.     void Start()
  16.     {
  17.         // Get the rigid body that we added in Unity.
  18.         memberRigidBody = this.GetComponent<Rigidbody2D>();
  19.     }
  20.  
  21.     // Update is called once per frame
  22.     void Update()
  23.     {
  24.         // Which direction does the player want to go?
  25.         // Assume the player doesn't want to move, so no direction.
  26.  
  27.         Vector3 localWhichDirection;
  28.         localWhichDirection = Vector3.zero;
  29.  
  30.         if (Input.GetKey(KeyCode.LeftArrow))
  31.         {
  32.             // if the player presses the left cursor key, player should walk left.
  33.            
  34.             localWhichDirection = Vector3.left;
  35.         }
  36.         else
  37.         if (Input.GetKey(KeyCode.RightArrow))
  38.         {
  39.             // if the player presses the right cursor key, player should walk right.
  40.              
  41.             localWhichDirection = Vector3.right;
  42.         }
  43.  
  44.         if (Input.GetKey(KeyCode.UpArrow))
  45.         {
  46.             // if the player presses the up cursor key, player should walk up.
  47.  
  48.             localWhichDirection = Vector3.up;
  49.         }
  50.         else
  51.        if (Input.GetKey(KeyCode.DownArrow))
  52.         {
  53.             // if the player presses the right cursor key, player should walk down.
  54.  
  55.             localWhichDirection = Vector3.down;
  56.         }
  57.     }
  58. }
  59.  
Tags: Unity
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement