Hello,
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
Thanks
CL