- Home /
Class functions don't seem to be updating class variables
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;
}
}
}
Comment
Answer by Bunny83 · Jul 30, 2018 at 03:07 PM
The way you described your problem is impossible. Even without testing i can asure that this would work as expected. Have you tried adding a Debug.Log to your SetNode method? Maybe you call it from somewhere else when you press the right mouse button?