Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Main : MonoBehaviour {
- public Sprite [] Ninjawalk;
- public float Moveframeindex = 1.0f;
- public float CharPositionXInBlocks;
- public float CharPositionYInBlocks;
- private int spriteindex;
- private Vector3 CharPosition;
- private bool MovesetD = true;
- private bool MovesetA = true;
- private bool MovesetW = true;
- private bool MovesetS = true;
- private int buttonlock = 0;
- // Use this for initialization
- void Start () {
- }
- // Update is called once per frame
- void Update () {
- //TODO Paste to notes ( Handy script to determin and designate screen size )
- //float mousePosInBlocks = Input.mousePosition.x / Screen.width;
- //print (mousePosInBlocks);
- //Sprite managment
- spriteindex = (int) Moveframeindex -1;
- CharPositionXInBlocks = this.transform.position.x ;
- CharPositionYInBlocks = this.transform.position.y ;
- //Movement controls
- //TODO Move in all directions AND jump and also make idle depending on last facing direction
- // IDLE
- //if (buttonlock == 0) { //TODO if buttonlock equals idle right and idle left as well as idle up and down
- //Moveframeindex = 1f;
- // this.GetComponent <SpriteRenderer>().sprite = Ninjawalk [spriteindex];
- //}
- if (Input.GetKeyUp(KeyCode.D)){ //---------------------------D
- MovesetD = true;
- buttonlock = 0;
- }
- if (Input.GetKey(KeyCode.D)) {
- if (buttonlock == 0) {
- buttonlock = 1;
- } else {
- if (buttonlock == 1) {
- if (MovesetD == true) {
- Moveframeindex = 7f;
- MovesetD = false;
- }
- Moveright();
- }
- }
- }
- if (Input.GetKeyUp(KeyCode.A)){ //---------------------------A
- MovesetA = true;
- buttonlock = 0;
- }
- if (Input.GetKey(KeyCode.A)) {
- if (buttonlock == 0) {
- buttonlock = 2;
- } else {
- if (buttonlock == 2) {
- if (MovesetA == true) {
- Moveframeindex = 11f;
- MovesetA = false;
- }
- Moveleft();
- }
- }
- }
- if (Input.GetKeyUp(KeyCode.W)){ //---------------------------W
- MovesetW = true;
- buttonlock = 0;
- }
- if (Input.GetKey(KeyCode.W)) {
- if (buttonlock == 0) {
- buttonlock = 3;
- } else {
- if (buttonlock == 3) {
- if (MovesetW == true) {
- Moveframeindex = 15f;
- MovesetW = false;
- }
- Moveup();
- }
- }
- }
- if (Input.GetKeyUp(KeyCode.S)){ //---------------------------S
- MovesetS = true;
- buttonlock = 0;
- }
- if (Input.GetKey(KeyCode.S)) {
- if (buttonlock == 0) {
- buttonlock = 4;
- } else {
- if (buttonlock == 4) {
- if (MovesetS == true) {
- Moveframeindex = 19f;
- MovesetS = false;
- }
- Movedown();
- }
- }
- }
- }
- void Moveright () {
- Moveframeindex += 0.12f;
- if (Ninjawalk [spriteindex]) {
- this.GetComponent <SpriteRenderer>().sprite = Ninjawalk [spriteindex];
- CharPositionXInBlocks += 0.05f;
- CharPosition = new Vector3 (CharPositionXInBlocks, this.transform.position.y, 0f);
- CharPosition.x = Mathf.Clamp(CharPosition.x, -3.60f, 3.65f);
- this.transform.position = CharPosition;
- }
- if (Moveframeindex >= 10.9f) {
- Moveframeindex = 7f;
- }
- }
- void Moveleft () {
- Moveframeindex += 0.12f;
- if (Ninjawalk [spriteindex]) {
- this.GetComponent <SpriteRenderer>().sprite = Ninjawalk [spriteindex];
- CharPositionXInBlocks -= 0.05f;
- CharPosition = new Vector3 (CharPositionXInBlocks, this.transform.position.y, 0f);
- CharPosition.x = Mathf.Clamp(CharPosition.x, -3.60f, 3.65f);
- this.transform.position = CharPosition;
- }
- if (Moveframeindex >= 14.9f) {
- Moveframeindex = 12f;
- }
- }
- void Moveup () {
- Moveframeindex += 0.12f;
- if (Ninjawalk [spriteindex]) {
- this.GetComponent <SpriteRenderer>().sprite = Ninjawalk [spriteindex];
- CharPositionYInBlocks += 0.05f;
- CharPosition = new Vector3 (this.transform.position.x, CharPositionYInBlocks, 0f);
- CharPosition.y = Mathf.Clamp(CharPosition.y, -2.60f, 2.6f);
- this.transform.position = CharPosition;
- }
- if (Moveframeindex >= 18.9f) {
- Moveframeindex = 15f;
- }
- }
- void Movedown () {
- Moveframeindex += 0.12f;
- if (Ninjawalk [spriteindex]) {
- this.GetComponent <SpriteRenderer>().sprite = Ninjawalk [spriteindex];
- CharPositionYInBlocks -= 0.05f;
- CharPosition = new Vector3 (this.transform.position.x, CharPositionYInBlocks, 0f);
- CharPosition.y = Mathf.Clamp(CharPosition.y, -2.6f, 2.6f);
- this.transform.position = CharPosition;
- }
- if (Moveframeindex >= 22.9f) {
- Moveframeindex = 19f;
- }
- }
- }
Add Comment
Please, Sign In to add comment