You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.4 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Arrow : MonoBehaviour
{
public Vector2 StartPoint;
private Vector2 EndingPoint;
private RectTransform arrow;
private float ArrowLength;
private float ArrowTheta;
private Vector2 ArrowPostion;
// Start is called before the first frame update
void Start()
{
arrow = transform.GetComponent<RectTransform>();
}
// Update is called once per frame
void Update()
{
//计算变量
EndingPoint = Input.mousePosition - new Vector3(1280.0f, 720.0f, 0.0f);//和分辨率有关位置在game画面中以左下角为原点而我们设计画面则以中心原点
ArrowLength = Mathf.Sqrt((EndingPoint.x - StartPoint.x) * (EndingPoint.x - StartPoint.x) + (EndingPoint.y - StartPoint.y) * (EndingPoint.y - StartPoint.y)) - 60;
ArrowPostion = new Vector2((EndingPoint.x + StartPoint.x) / 2, (EndingPoint.y + StartPoint.y) / 2);
ArrowTheta = Mathf.Atan2((EndingPoint.y - StartPoint.y), (EndingPoint.x - StartPoint.x));
//赋值
arrow.localPosition = ArrowPostion;
arrow.sizeDelta = new Vector2(ArrowLength, arrow.sizeDelta.y);
arrow.localEulerAngles = new Vector3(0.0f, 0.0f, ArrowTheta * 180 / Mathf.PI);
}
public void SetStartPoint(Vector2 _startPoint)
{
StartPoint = _startPoint - new Vector2(1280.0f, 720.0f);
}
}