I returned to my old drawing game after a year or so off, and it worked fine with my unity 5.4. But after i updated it to 5.6.1 my line renderer that im using to draw has changed. For some reason it connects a line to the center of the screen nomatter where last line position is, anyone know the reasn for this? Attached is a picture of the issue and here is some of the code:
The class that draws the lines.
using System;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class DotTimer : MonoBehaviour
{
private int thisID;
private LineRenderer lineRenderer;
private float counter;
private float distance;
public float lineDrawSpeed = 0.5f;
private Transform origin;
private Transform destination;
void Start()
{
GameObject aScript = GameObject.Find("DotSpawner");
scriptSpawnDot myDotSpawnClass = aScript.GetComponent<scriptSpawnDot>();
thisID = myDotSpawnClass.dotID;
myDotSpawnClass.dotID += 1;
Destroy(gameObject, 3);
this.name = thisID.ToString();
if (thisID != 1)
{
startLineRenderer();
}
}
void Update()
{
if (thisID != 1)
{
updateLineRenderer();
}
}
void startLineRenderer()
{
// For debugging
Debug.Log("this id:" + thisID);
int lookForThisObject = thisID -= 1;
GameObject lookingForThisObject = GameObject.Find(lookForThisObject.ToString());
origin = lookingForThisObject.transform;
destination = transform;
// For debugging
Debug.Log("looking for this object: " + lookForThisObject);
lineRenderer = GetComponent<LineRenderer>();
lineRenderer.SetPosition(0, origin.position);
lineRenderer.SetWidth(.02f, .02f);
lineRenderer.SetVertexCount(2);
distance = Vector3.Distance(origin.position, destination.position);
}
void updateLineRenderer()
{
if (counter < distance)
{
counter += .1f / lineDrawSpeed;
float x = Mathf.Lerp(0, distance, counter);
Vector3 pointA = origin.position;
Vector3 pointB = destination.position;
lineRenderer.SetPosition(1, destination.position);
}
}
}