Search code examples
c#.netvariableseventhandlerclass-fields

Why is the private int variable in this c# program not updating?


Here's the program:

   [SerializeField] ARPointCloudManager mArPointCloudManager;
   private int numPointsUpdated = 0;

    // Start is called before the first frame update
    void Start()
    {

        UpdateTextPlanes();

        mArPointCloudManager.pointCloudsChanged += onPointCloudsChanged;

    }

    // Update is called once per frame
    void Update()
    {

        UpdateTextPlanes();

    }

    void onPointCloudsChanged(ARPointCloudChangedEventArgs args)
    {

        foreach (var pointCloudUpdated in args.updated)
        {
            numPointsUpdated += 1;
        }

    }

    private void UpdateTextPlanes()
    {
        PlaneText.SetText(" Point Clouds Updated = " + numPointsUpdated);
    }

The values of the private int variable remains zero & i don't understand why it's happening. I tried making the variable static & placing it at the top of my class before everything else but that didn't make any difference. I've searched around a lot but i can't find either solutions or explanations. I'm a beginner.


Solution

  • The problem was resolved when i wired all of the variables correctly in my unity project.