Aiming to an object (iphone game)


I am quite stuck in this matter.

I am trying to fire a ray from a cube to a game object in an Iphone via touch in order to allow the player to aim at an object.

I try different solution but I learn that draw.line works online with gizmos, and GL do not work in iOS platforms

So I did try this solution after search in all documents in Unity

However I did maker it work in my PC but when I put the touch part it all stuck.

Please any advice will be great since is one week I am stuck in this

This is my script:

public class Linerender : MonoBehaviour

	private LineRenderer lineRenderer;
	private float counter;
	private float dist;

	public Transform origin;
	public Transform destination;

	public float lineDrawSpeed = 6f;

	void Start () 
		lineRenderer = GetComponent<LineRenderer> ();
		lineRenderer.SetPosition (0, origin.position);
		lineRenderer.SetWidth (.45f, .45f);
	void Update ()
				//loop through all the touches on the screen 
				for(int i = 0 ; i < Input.touchCount; i++)
					if (Input.touchCount > 0 && Input.GetTouch (0).phase == TouchPhase.Stationary)

						dist = Vector3.Distance(origin.position, destination.position);

						if(counter < dist)
							counter += .1f / lineDrawSpeed;

							float x = Mathf.Lerp(0, dist, counter);
							Vector3 pointA = origin.position;
							Vector3 pointB = Input.GetTouch(0).position;

						//get the unit vector in the desired direction, multiplay by the desired leght and add the staring point 

							Vector3 pointAlongLine = x * Vector3.Normalize(pointB - pointA) + pointA;

							lineRenderer.SetPosition(1, pointAlongLine);


Any help please. I would describe myself as desperate.
I did try several way but when I put the touch part it simply doesn’t work



Touch works in Screen coordinates. LineRenderer works is world coordiantes. You have to convert between the two. How you do that conversion will depend on the kind of camera (Orthographic vs Perspective), and the rotation of the camera. If the camera has rotation (0,0,0), and the object plane is 10 units in front of the camera, you would do:

Vector3 pointB = Input.GetTouch(0).position;
pointB.z = 10;
pointB = Camera.main.ScreenToWorldPoint(pointB);

Note your code is using Input.GetTouch(0). This means for all the touches, you are only processing the first touch. So either you should dispense with the for() loop and just process the first touch if touchCount > 0, or you would use Input.GetTouch(i). The latter would require a LineRenderer for each touch.