Advertisement
renderbydavid

Movement

Oct 22nd, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.58 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Movement : MonoBehaviour
  6. {
  7.     public Transform Mover;
  8.     [HideInInspector]
  9.     public bool SomethingInTheWay;
  10.     [HideInInspector]
  11.     public string TagOfObject;
  12.     public Animator MyAnims;
  13.     public string Who;
  14.     public void MoveLeft()
  15.     {
  16.         RaycastHit2D left = Physics2D.Raycast(transform.position, Vector2.left, .40f, 1 << 0);
  17.         if (left)
  18.         {
  19.             SomethingInTheWay = true;
  20.             TagOfObject = left.transform.tag;
  21.         }
  22.         else
  23.         {
  24.             Mover.transform.position = new Vector2(Mover.transform.position.x - 1 * Time.deltaTime * 2,
  25.     Mover.transform.position.y);
  26.             SomethingInTheWay = false;
  27.         }
  28.     }
  29.     public void MoveRight()
  30.     {
  31.         RaycastHit2D Right = Physics2D.Raycast(transform.position, Vector2.right, .40f, 1 << 0);
  32.         if (Right)
  33.         {
  34.             SomethingInTheWay = true;
  35.             TagOfObject = Right.transform.tag;
  36.         }
  37.         else
  38.         {
  39.             Mover.transform.position = new Vector2(Mover.transform.position.x + 1 * Time.deltaTime * 2,
  40.     Mover.transform.position.y);
  41.             SomethingInTheWay = false;
  42.         }
  43.     }
  44.     public void MoveUp()
  45.     {
  46.         RaycastHit2D Up = Physics2D.Raycast(transform.position, Vector2.up, .40f, 1 << 0);
  47.         if (Up)
  48.         {
  49.             SomethingInTheWay = true;
  50.             TagOfObject = Up.transform.tag;
  51.         }
  52.         else
  53.         {
  54.             Mover.transform.position = new Vector2(Mover.transform.position.x,
  55.     Mover.transform.position.y + 1 * Time.deltaTime * 2);
  56.             SomethingInTheWay = false;
  57.         }
  58.     }
  59.     public void MoveDown()
  60.     {
  61.         RaycastHit2D down = Physics2D.Raycast(transform.position, Vector2.down, .40f, 1 << 0);
  62.         if (down)
  63.         {
  64.             SomethingInTheWay = true;
  65.             TagOfObject = down.transform.tag;
  66.         }
  67.         else
  68.         {
  69.             Mover.transform.position = new Vector2(Mover.transform.position.x,
  70.     Mover.transform.position.y - 1 * Time.deltaTime * 2);
  71.             SomethingInTheWay = false;
  72.         }
  73.     }
  74.  
  75.     public void Idle()
  76.     {
  77.         //Moveer is idle
  78.     }
  79.  
  80.     public void IdleDown()
  81.     {
  82.         MyAnims.Play(Who + "IdleDown");
  83.     }
  84.     public void IdleUp()
  85.     {
  86.         MyAnims.Play(Who + "IdleUp");
  87.     }
  88.     public void IdleLeft()
  89.     {
  90.         MyAnims.Play(Who + "IdleLeft");
  91.     }
  92.     public void IdleRight()
  93.     {
  94.         MyAnims.Play(Who + "IdleRight");
  95.     }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement