::I have been using the Terrasqual joystick on my Vampire survivors clone, and i came to realise that the joystick used in the tutorials doenst have the option to disappear when not pressed like vampire survivors and many other games, i tried to make something similar (not really good with c# scripting) and i made a system that makes it “disappear” when not used for x amount of time
basically, when not used for x amount of time the joystick gets teleported of screen, and by using “Snaps to Touch” it gets back on the screen.
the problem with this approach is that for example, if i make the joystick teleport off the screen on the left, the next time i click on the screen, the character will move to the right, as the joystick is being called left to right
i know that this approach have a lot of issues, send your suggestion!
VirtualJoystick.cs
//existing code...
private float lastUsedAt;
public float idleTime = 0.1f; //amount of time that it takes for the joystick to disappear
//existing code...
void Update(){
//existing code...
if (axis.sqrMagnitude > 0)
{
lastUsedAt = Time.time;
}
if (Time.time - lastUsedAt >= idleTime) {
gameObject.SetActive(false); //disable the object so that works properly when teleported
transform.position = new Vector3(-720, 0, 0); // teleports of screen
gameObject.SetActive(true); //activate it again
}
}