Commenting script help

Hi,
Can anyone help with my commenting for this script?
I have managed to comment all my other scripts explaining what the code is doing but I am having trouble with this one. It is the scrolling for my game, I followed tutorials for this section but unsure how to explain the code correctly.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ScrollParallex : MonoBehaviour
{
    public float FOV = 19;
    int leftIndex, rightIndex;
    Transform cameraT;
    Transform[] parallexLayers;

    // Start is called before the first frame update
    void Start()
    {
        cameraT = Camera.main.transform;
        parallexLayers = new Transform[transform.childCount];
        for (int index = 0; index < transform.childCount; index++)
        {
            parallexLayers[index] = transform.GetChild(index);
        }
        leftIndex = 0;
        rightIndex = parallexLayers.Length - 1;
    }

    // Update is called once per frame
    void Update()
    {
        if (cameraT.position.x < (parallexLayers[leftIndex].position.x + FOV))
        {
            moveBackgroundLeft();
        }
        if (cameraT.position.x > (parallexLayers[rightIndex].position.x + FOV))
        {
            moveBackgroundRight();
        }
    }

    void moveBackgroundLeft()
    {
        parallexLayers[rightIndex].position = Vector3.right * (parallexLayers[leftIndex].position.x - FOV);
        leftIndex = rightIndex;
        rightIndex -= 1;
        checkIndex();

    }

    void moveBackgroundRight()
    {
        parallexLayers[leftIndex].position = Vector3.right * (parallexLayers[rightIndex].position.x + FOV);
        rightIndex = leftIndex;
        leftIndex += 1;
        checkIndex();
    }

    void checkIndex()
    {
        if (leftIndex == parallexLayers.Length)
        {
            leftIndex = 0;
        }
        if (rightIndex < 0)
        {
            rightIndex = parallexLayers.Length - 1;
        }
    }

}

If any third party person can comment a script, then the script doesn’t need comments.

If a script needs comments, really the only person who can do it is the guy who wrote the script, or else someone forensically studying the code trying to track down what it does, which is what you traditionally pay hundreds of dollars an hour to a software engineer to do for you. :slight_smile:

3 Likes