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 Player : MonoBehaviour {
- public GameObject player;
- private Vector2 _currentMousePosition;
- public Transform target;
- void Start()
- {
- }
- void Update()
- {
- if (Input.GetMouseButtonDown(0))
- {
- Vector3 mousePos = Input.mousePosition;
- Vector3 objPos = Camera.main.WorldToScreenPoint(transform.position);
- mousePos.x -= objPos.x;
- mousePos.y -= objPos.y;
- float angle = Mathf.Atan2(mousePos.y, mousePos.x) * Mathf.Rad2Deg;
- Debug.Log(angle);
- if (angle <= 45 && angle >= -45)
- {
- player.transform.position = new Vector2(player.transform.position.x + 1, player.transform.position.y);
- }
- if (angle >= 45 && angle <= 135)
- {
- player.transform.position = new Vector2(player.transform.position.x, player.transform.position.y + 1);
- }
- if (angle >= 135 && angle <= -135)
- {
- player.transform.position = new Vector2(player.transform.position.x - 1, player.transform.position.y);
- }
- if (angle >= -135 && angle <= -45)
- {
- player.transform.position = new Vector2(player.transform.position.x, player.transform.position.y - 1);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement