Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Movement : MonoBehaviour
- {
- public Transform Mover;
- [HideInInspector]
- public bool SomethingInTheWay;
- [HideInInspector]
- public string TagOfObject;
- public Animator MyAnims;
- public string Who;
- public void MoveLeft()
- {
- RaycastHit2D left = Physics2D.Raycast(transform.position, Vector2.left, .40f, 1 << 0);
- if (left)
- {
- SomethingInTheWay = true;
- TagOfObject = left.transform.tag;
- }
- else
- {
- Mover.transform.position = new Vector2(Mover.transform.position.x - 1 * Time.deltaTime * 2,
- Mover.transform.position.y);
- SomethingInTheWay = false;
- }
- }
- public void MoveRight()
- {
- RaycastHit2D Right = Physics2D.Raycast(transform.position, Vector2.right, .40f, 1 << 0);
- if (Right)
- {
- SomethingInTheWay = true;
- TagOfObject = Right.transform.tag;
- }
- else
- {
- Mover.transform.position = new Vector2(Mover.transform.position.x + 1 * Time.deltaTime * 2,
- Mover.transform.position.y);
- SomethingInTheWay = false;
- }
- }
- public void MoveUp()
- {
- RaycastHit2D Up = Physics2D.Raycast(transform.position, Vector2.up, .40f, 1 << 0);
- if (Up)
- {
- SomethingInTheWay = true;
- TagOfObject = Up.transform.tag;
- }
- else
- {
- Mover.transform.position = new Vector2(Mover.transform.position.x,
- Mover.transform.position.y + 1 * Time.deltaTime * 2);
- SomethingInTheWay = false;
- }
- }
- public void MoveDown()
- {
- RaycastHit2D down = Physics2D.Raycast(transform.position, Vector2.down, .40f, 1 << 0);
- if (down)
- {
- SomethingInTheWay = true;
- TagOfObject = down.transform.tag;
- }
- else
- {
- Mover.transform.position = new Vector2(Mover.transform.position.x,
- Mover.transform.position.y - 1 * Time.deltaTime * 2);
- SomethingInTheWay = false;
- }
- }
- public void Idle()
- {
- //Moveer is idle
- }
- public void IdleDown()
- {
- MyAnims.Play(Who + "IdleDown");
- }
- public void IdleUp()
- {
- MyAnims.Play(Who + "IdleUp");
- }
- public void IdleLeft()
- {
- MyAnims.Play(Who + "IdleLeft");
- }
- public void IdleRight()
- {
- MyAnims.Play(Who + "IdleRight");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement