I would like to recreate the interface effect in the following video.
I’m talking about the arrows that are pointing toward the mouse icon from the center of the screen when the ship turns.
I’m not sure what would be the best way to do this so I’m in quest for advices
In Update(), set Image1’s Z rotation to the angle between Vector3.left and the vector from the center of the screen to the mouse, and set the width to the mouse vector’s magnitude:
using UnityEngine;
public class Aimer : MonoBehaviour
{
private RectTransform rectTransform;
private void Awake()
{
rectTransform = GetComponent<RectTransform>();
}
void Update()
{
var center = new Vector2(Screen.width / 2, Screen.height / 2);
var mouseVector = new Vector2(center.x - Input.mousePosition.x, center.y - Input.mousePosition.y);
var angle = Vector2.Angle(Vector2.left, mouseVector);
if (Input.mousePosition.y < center.y) angle = -angle;
rectTransform.localRotation = Quaternion.Euler(0, 0, angle);
rectTransform.sizeDelta = new Vector2(mouseVector.magnitude, 40);
}
}