- Home /
 
Drawing 2 lines in same time
hi, im now currently making a drawing game using a method to draw lines but i do not know is it the best way to do what i am up to is to create an object which with line renderer with it, the object is following my touch as i move along, it completly works with if only 1 line is drawing however i need it to be 2 line drawing most likely at the same time, so i can draw 2 line seperately.
the following is my coding
 using UnityEngine;
 using System.Collections;
 
 public class TouchDrawMethod : MonoBehaviour {
         
     public GameObject trailPrefabsR;
     public GameObject trailPrefabsL;
 
     bool canMoveR;
     bool canMoveL;
 
     void Start(){
         canMoveR = false;
     }
 
     void Update(){
 
              touchMethod();
 
     }
     
     void touchMethod(){
 
         int count = Input.touchCount;
         for(int i=0; i < count; i++){
             
             Touch touch = Input.GetTouch(i);
 
             if(touch.phase == TouchPhase.Began){
 
                 if(i == 0){
                 if(touch.position.x < Screen.width){
                     trailPrefabsR.transform.position = new Vector3((touch.position.x /Screen.width)*16 -8 , (touch.position.y / Screen.height) * 10-5, -8);
                     Instantiate(trailPrefabsR, trailPrefabsR.transform.position, transform.rotation);
                     canMoveR = true;
                     }
                 } else{
                     trailPrefabsL.transform.position = new Vector3((touch.position.x /Screen.width)*16 -8 , (touch.position.y / Screen.height) * 10-5, -8);
                     Instantiate(trailPrefabsL, trailPrefabsL.transform.position, transform.rotation);
                     canMoveL = true;
                 }
             }
 
             if(touch.phase == TouchPhase.Ended){
                 GameObject.FindWithTag("Right").tag = "null";
                 GameObject.FindWithTag("Left").tag = "null";
                 canMoveR = false;
                 canMoveL = false;
             }
 
             
             if (GameObject.FindWithTag ("Right") != null) {
                 
                 if (canMoveR)
                     GameObject.FindWithTag ("Right").transform.position = new Vector3 ((touch.position.x /Screen.width)*16 -8, (touch.position.y / Screen.height) *10 -5, -8);
                 else
                     GameObject.FindWithTag ("Right").transform.position = new Vector3 ((touch.position.x /Screen.width)*16 -8, (touch.position.y / Screen.height) *10 -5, 10);
             
             }
 
             if (GameObject.FindWithTag ("Left") != null) {
                 
                 if (canMoveR)
                     GameObject.FindWithTag ("Left").transform.position = new Vector3 ((touch.position.x /Screen.width)*16 -8, (touch.position.y / Screen.height) *10 -5, -8);
                 else
                     GameObject.FindWithTag ("Left").transform.position = new Vector3 ((touch.position.x /Screen.width)*16 -8, (touch.position.y / Screen.height) *10 -5, 10);
                 
             }
 
         }
     }
 }
 
 
               with this, i can only draw 1 line at once although it detect there is two touch and instantiating 2 of my line renderer object, i think the problem is, it update my two touch point into same place thats why i cannot draw two line in the same time, it would be great if any of you can help me with this problem solving or any other better way to draw 2 lines in same time thankyou
i just think of a method, can i do it as
 touch.fingerId.position
 
                  but this comes me with an error, is this such a way to do or my code is something wrong?
Your answer