Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class HeroScript : MonoBehaviour
- {
- // Set my Speed. If There is no speed, you can't move.
- [SerializeField] private float memberSpeed = 10.0f;
- // I still don't know.
- private SpriteRenderer memberSpriteRenderer = null;
- // I STILL don't know. Rigid Body.
- private Rigidbody2D memberRigidBody = null; // I don't know, I'll tell you later.
- // Start is called before the first frame update
- void Start()
- {
- // Get the rigid body that we added in Unity.
- memberRigidBody = this.GetComponent<Rigidbody2D>();
- }
- // Update is called once per frame
- void Update()
- {
- // Which direction does the player want to go?
- // Assume the player doesn't want to move, so no direction.
- Vector3 localWhichDirection;
- localWhichDirection = Vector3.zero;
- if (Input.GetKey(KeyCode.LeftArrow))
- {
- // if the player presses the left cursor key, player should walk left.
- localWhichDirection = Vector3.left;
- }
- else
- if (Input.GetKey(KeyCode.RightArrow))
- {
- // if the player presses the right cursor key, player should walk right.
- localWhichDirection = Vector3.right;
- }
- if (Input.GetKey(KeyCode.UpArrow))
- {
- // if the player presses the up cursor key, player should walk up.
- localWhichDirection = Vector3.up;
- }
- else
- if (Input.GetKey(KeyCode.DownArrow))
- {
- // if the player presses the right cursor key, player should walk down.
- localWhichDirection = Vector3.down;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement