There will be a button on which the icon of the active weapon will be displayed (I think I will do this)
And when pressed, it will reload. But when Clamping, a circular panel will be activated on which several weapons will be displayed and you can choose which one. How to implement it
The button will not disappear. Driving on it will be selected weapons from the circle
For example, hold down the button and down, then the main weapon is activated. How to make such a circle?
I found a video and wrote part of the script from it. the rest is cursor tracking. but I have an android game. how can I track the position of the finger on the button?
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace wheel.Scripts
{
public class WeaponWheel : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
[SerializeField] private GameObject whellParent;
[SerializeField] private bool _buttonPressed;
public bool isButtonPresed => _buttonPressed;
[Serializable] public class Wheel
{
public Sprite highlightWhell;
private Sprite m_normallWhell;
public Image wheel;
public Sprite NormalSprite
{
get => m_normallWhell;
set => m_normallWhell = value;
}
}
[SerializeField] private Wheel[] wheels = new Wheel[4];
[Header("Dots & Lines")]
[SerializeField] private Transform[] dots = new Transform[4];
private Vector2[] pos = new Vector2[4];
private Vector2 start, end;
private Vector2 mousePos;
private void EnableLightWhell(int index)
{
for (int i = 0; i < wheels.Length; i++)
{
if (wheels[i].wheel != null && wheels[i].highlightWhell != null)
{
if (i == index)
wheels[i].wheel.sprite = wheels[i].highlightWhell;
else
wheels[i].wheel.sprite = wheels[i].NormalSprite;
}
}
}
private void DisableLightWhell()
{
for (int i = 0; i < wheels.Length; i++)
{
if (wheels[i].wheel != null)
wheels[i].wheel.sprite = wheels[i].NormalSprite;
}
}
public void OnPointerDown(PointerEventData eventData)
{
_buttonPressed = true;
}
public void OnPointerUp(PointerEventData eventData)
{
_buttonPressed = false;
}
public void Start()
{
DisableWhell();
for (int i = 0; i < wheels.Length; i++)
{
if (wheels[i].wheel != null)
{
wheels[i].NormalSprite = wheels[i].wheel.sprite;
}
}
}
private void EnableWhell()
{
if (whellParent != null)
whellParent.SetActive(true);
}
private void DisableWhell()
{
if (whellParent != null)
whellParent.SetActive(false);
}
private void Update()
{
if (_buttonPressed)
{
EnableWhell();
}
else if (!_buttonPressed)
{
DisableWhell();
}
}
}
}
Perhaps by looking at the data inside of the PointerEventData
you receive?
Another class that may be useful here is RectTransformUtility