Ok Ive在一个将图像设置为射线投射的容器内,做了一个3个按钮的放射状菜单:
我希望按钮“单击”,将一些颜色锁定在名为Ive的灰色图像上,并设置在画布的一角。我已经将此脚本添加到了整个容器中,并且在我第一次拖动时几乎无法工作:
[SerializeField]
private float turnSpeed = 5;
/// <summary>
/// Movement.
/// </summary>
private Vector2 movement;
void Update()
{
Vector2 currentPosition = transform.position;
#if UNITY_EDITOR
if (Input.GetButton("Fire1"))
{
Vector2 moveTowards = Camera.main.ScreenToWorldPoint(Input.mousePosition);
movement = moveTowards - currentPosition;
movement.Normalize();
}
#else
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Moved)
{
Vector2 moveTowards = Camera.main.ScreenToWorldPoint(touch.position);
movement = moveTowards - currentPosition;
movement.Normalize();
}
}
#endif
float targetAngle = Mathf.Atan2(movement.y, movement.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Slerp(transform.rotation,
Quaternion.Euler(0, 0, targetAngle),
turnSpeed * Time.deltaTime);
}
}
此后不执行任何操作,并且按钮的交互性会干扰任何拖动。我不认为我正在正确地解决这个问题,也不知道如何将“锁定/自动收报机条”与灰色方框结合在一起。
如何创建这样的动画径向菜单?