- Home /
Is there a way to get the actual joystick.Vertical and joystick.Horizontal Value?,
First, sorry for my bad english. I'm 15, and I'm trying to make a moba game by my own.
What I want to do is 1. Pass a parameter called joystick_tag. (like this: Get3DJoystickPosition(joystick_tag)) 2. Get current joystick.Horizontal, joystick.Vertical, Camera.main so that I can calculate the value
Camera.main.ScreenToWorldPoint(new Vector3((joystick.Horizontal + 1) * Screen.width / 2, (joystick.Vertical + 1) * Screen.height / 2, Camera.main.nearClipPlane));
return that value.
It seems quite simple, but in my code the joystick.Horizontal and the joystick.Vertical value keeps 0 even if i move the joystick.
Basically, the method gets a string input, called joystick_tag. then by the tag, every time the method gets called, it finds a joystick tagged by the tag. Then it calls the Update() method so that I can get the current joystick.Horizontal and joystick.Vertical.
This is the full code. Joystick class is from the Joystick Pack by Fenerax studios.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Korselo.JoyPos
{
public class JoyPos : MonoBehaviour
{
public Joystick joystick;
public Vector3 world_v;
public string joystick_tag_public;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
world_v = Camera.main.ScreenToWorldPoint(new Vector3((joystick.Horizontal + 1) * Screen.width / 2, (joystick.Vertical + 1) * Screen.height / 2, Camera.main.nearClipPlane));
Debug.Log(world_v);
}
public Vector3 Get3DJoystickPosition(string joystick_tag)
{
GameObject joystickGameObject = GameObject.FindGameObjectWithTag(joystick_tag);
if (joystickGameObject != null)
{
joystick = joystickGameObject.GetComponent<Joystick>();
}
Update();
return world_v;
}
}
}
,First, sorry for my bad english. I'm 15, and I'm trying to make a moba game by my own.
What I want to do is 1. Pass a parameter called joystick_tag. (like this: Get3DJoystickPosition(joystick_tag)) 2. Get current joystick.Horizontal, joystick.Vertical, Camera.main so that I can calculate the value Camera.main.ScreenToWorldPoint(new Vector3((joystick.Horizontal + 1) * Screen.width / 2, (joystick.Vertical + 1) * Screen.height / 2, Camera.main.nearClipPlane));
3. return that value.
It seems quite simple, but in my code the joystick.Horizontal and the joystick.Vertical value keeps 0 even if i move the joystick.
Basically, the method gets a string input, called joystick_tag. then by the tag, every time the method gets called, it finds a joystick tagged by the tag. Then it calls the Update() method so that I can get the current joystick.Horizontal and joystick.Vertical.
This is the full code. Joystick class is from the Joystick Pack by Fenerax studios. using System.Collections; using System.Collections.Generic; using UnityEngine;
namespace Korselo.JoyPos
{
public class JoyPos : MonoBehaviour
{
public Joystick joystick;
public Vector3 world_v;
public string joystick_tag_public;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
world_v = Camera.main.ScreenToWorldPoint(new Vector3((joystick.Horizontal + 1) * Screen.width / 2, (joystick.Vertical + 1) * Screen.height / 2, Camera.main.nearClipPlane));
Debug.Log(world_v);
}
public Vector3 Get3DJoystickPosition(string joystick_tag)
{
GameObject joystickGameObject = GameObject.FindGameObjectWithTag(joystick_tag);
if (joystickGameObject != null)
{
joystick = joystickGameObject.GetComponent<Joystick>();
}
Update();
return world_v;
}
}
}
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Making an array that contains object with one of 2 tags 2 Answers
Change gameobject tag when player collides with another gameobject 1 Answer
Is there a way to get the actual joystick.Vertical and joystick.Horizontal Value?, 1 Answer