- Home /
 
               Question by 
               NopkarCraft · Oct 05, 2019 at 12:29 PM · 
                c#androidjoystick  
              
 
              Android Joystick in Camera
Hey
I tried to make a Joystick in screen to move my 2D Character, but never works
So I had to search a video and.... I found and Works
But the video use a position fixed, and I can't move the camera with the character
I need so much this Joystick, but working when camera move
Video Link: https://www.youtube.com/watch?v=uVxnvXonGXY
Code:
 public Transform player;
 public int veloc;
 public bool toqueStart;
 public Vector2 pontoA;
 public Vector2 pontoB;
 public Transform Circulo;
 public Transform AroCirculo;
 public int umSinal;
 public GameObject Corpitchu;
 public Animator animeCorpo;
 void Start () {
     veloc = 5;
     animeCorpo = Corpitchu.GetComponent<Animator>();
 }
 
 void Update () {
 
     if (Input.GetMouseButtonDown(0)){
         pontoA = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x , Input.mousePosition.y,
                                                             Camera.main.transform.position.z));
         Circulo.transform.position = pontoA * 1;
         AroCirculo.transform.position = pontoA * 1;
         Circulo.GetComponent<SpriteRenderer>().enabled = true;
         AroCirculo.GetComponent<SpriteRenderer>().enabled = true;
     }
     if (Input.GetMouseButton(0)){
         toqueStart = true;
         pontoB = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x , Input.mousePosition.y,
                                                             Camera.main.transform.position.z));
     }
     else{
         toqueStart = false;
     }
     if (pontoA.x < pontoB.x){
         GameObject.Find ("Corpo").transform.rotation = Quaternion.Euler(0,0,0);
         GameObject.Find("Conjunto").transform.rotation = Quaternion.Euler(0,0,0);
     }
     else{
         GameObject.Find("Corpo").transform.rotation = Quaternion.Euler(0,180,0);
         GameObject.Find("Conjunto").transform.rotation = Quaternion.Euler(0,180,0);
     }
 
 }
 void FixedUpdate () {
     if (toqueStart == true){
         Vector2 Deslocar = pontoB - pontoA;
         Vector2 Direcao = Vector2.ClampMagnitude(Deslocar, 1.0f);
         MovePlayer(Direcao);
         Circulo.transform.position = new Vector2 (pontoA.x + Direcao.x, pontoA.y + Direcao.y) * 1;
         if( (pontoB.x > pontoA.x + 0.15) || (pontoB.x < pontoA.x - 0.15) || 
            (pontoB.y > pontoA.y + 0.15) || (pontoB.y < pontoA.y - 0.15) ){
             animeCorpo.SetBool("BoraAndar", true);
         }
         
     }
     else{
         Circulo.GetComponent<SpriteRenderer>().enabled = false;
         AroCirculo.GetComponent<SpriteRenderer>().enabled = false;
         animeCorpo.SetBool("BoraAndar", false);
     }
 
 }
 void MovePlayer(Vector2 Direcao) {
     player.Translate(Direcao * veloc * Time.deltaTime);
 }
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
NullReferenceException: Object reference not set to an instance of an object 3 Answers
Multiple Cars not working 1 Answer
[Solved] Boolean is true and flase every frame 3 Answers
Distribute terrain in zones 3 Answers
Android C# JoyStick Movement 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                