The SetNode function works as it should, drawing a line between the startNode and endNode objects but then when after I set the start node object to null in the update function, in the SetNode function the startNode variable still has it’s value. It’s like the startNode variable in the SetNode function is acting like a local variable instead of the class wide variable but I don’t know why.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ArrowPlacer : MonoBehaviour {
private GameObject startNode;
private GameObject endNode;
void Start () {
}
void Update () {
if (Input.GetMouseButtonDown (1)) {
startNode = null;
}
}
public void SetNode(GameObject state){
if (startNode==null) {
startNode = state;
} else {
endNode = state;
LineRenderer line = startNode.GetComponent<LineRenderer> ();
line.SetPosition (0, startNode.transform.position);
line.SetPosition (1, endNode.transform.position);
startNode = null;
endNode = null;
}
}
}