mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/MI-38.git
synced 2026-01-23 23:55:38 +03:00
36 lines
1.1 KiB
C#
36 lines
1.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class pedals : MonoBehaviour
|
|
{
|
|
private Vector3 mousePosition;
|
|
public float moveSpeed = 1.2f;
|
|
|
|
|
|
|
|
|
|
|
|
void OnMouseDrag()
|
|
{
|
|
//mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
|
mousePosition = Camera.current.ScreenToWorldPoint(Input.mousePosition);
|
|
|
|
// вычисляем разницу между текущим положением и положением мыши
|
|
|
|
Vector3 difference = mousePosition - transform.position;
|
|
difference.Normalize();
|
|
// вычисляемый необходимый угол поворота
|
|
float rotation_z = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;
|
|
|
|
// Применяем поворот вокруг оси Z
|
|
if (rotation_z<45 && rotation_z>-45)
|
|
{
|
|
transform.localRotation = Quaternion.Euler(0f, 0f, rotation_z);
|
|
|
|
//int angle_int = Mathf.RoundToInt(rotation_z);
|
|
|
|
Debug.Log("угол"+ rotation_z);
|
|
}
|
|
}
|
|
} |