Hello,
I'm adding rotation function to an object based on following script: https://answers.unity.com/questions/716086/spin-a-2d-object-with-mouse-drag.html
using UnityEngine;
using UnityEngine.EventSystems;
public class Rotate : EventTrigger
{
float deltaRotation;
float previousRotation;
float currentRotation;
//float speed = 0.8f;
private bool dragging;
public GameObject pressedButton;
//float rotateSpeed = 100f;
/* void Start()
{
}*/
void Update()
{
if (dragging)
{
currentRotation = angleBetweenPoints(pressedButton.transform.position, Camera.main.ScreenToWorldPoint(Input.mousePosition));
deltaRotation = Mathf.DeltaAngle(currentRotation, previousRotation);
previousRotation = currentRotation;
pressedButton.transform.Rotate(Vector3.back, deltaRotation); // * Time.deltaTime
}
}
float angleBetweenPoints(Vector2 position1, Vector2 position2)
{
var fromLine = position2 - position1;
var toLine = new Vector2(1, 0);
var angle = Vector2.Angle …