Monday, November 7, 2022
HomeGame Developmentunity - Dynamic factors relies on line size

unity – Dynamic factors relies on line size


I am attempting to make a dynamic factors relying on line size, however I am unable to perceive the purpose of it. As you may see on image factors 1, 3 and a couple of, 4 has totally different size to the road factors. How might I make it change to identical worth? enter image description here

Grid.cs

public float xSize, ySize;

    [SerializeField] personal Vector3[] vertices;

    [SerializeField] personal LineManager lineManager;

    personal void Generate () {
        vertices = new Vector3[(int)((xSize + 1) * (ySize + 1))];

        for (int i = 0, y = 0; y <= ySize; y++) {
            for (int x = 0; x <= xSize; x++, i++) {
                vertices[i] = lineManager.FirstPointCoordinate() + new Vector3(x, y);
            }
        }
    }

    personal void Begin()
    {
        xSize = ySize = lineManager.pointDistance ;
        Generate();
    }

    personal void Replace()
    {
        xSize = ySize = lineManager.pointDistance ;
        Generate();
    }
    
    personal void OnDrawGizmos () {
        Gizmos.coloration = Coloration.black;
        for (int i = 0; i < vertices.Size; i++) {
            Gizmos.DrawSphere(vertices[i], 0.1f);
        }

        if (vertices == null) {
            return;
        }
    }
}

LineManager.cs

    [SerializeField] personal LineRenderer line;
    [SerializeField] personal Remodel[] factors;

    public float pointDistance;

    // Replace is known as as soon as per body

    void Begin()
    {
        line = Instantiate(line);
        for (int i = 0; i < factors.Size; i++)
        {
            line.SetPosition(i, factors[i].place);
            pointDistance = Vector3.Distance(factors[0].place + new Vector3(0.5f, 0.5f), factors[1].place - new Vector3(0.5f, 0.5f));
        }
    }
    void Replace()
    {
        for (int i = 0; i < factors.Size; i++)
        {
            line.SetPosition(i, factors[i].place);
            pointDistance = Vector3.Distance(factors[0].place + new Vector3(0.5f, 0.5f), factors[1].place - new Vector3(0.5f, 0.5f));
            Debug.Log(pointDistance);
        }
    }

    public void SetUpLine(Remodel[] factors)
    {
        line.positionCount = factors.Size;
        this.factors = factors;
    }

    public Vector3 FirstPointCoordinate()
    {
        return factors[0].rework.place + new Vector3(0.5f, 0.5f);
    }

    public Vector3 SecondPointCoordinate()
    {
        return factors[1].rework.place - new Vector3(0.5f, 0.5f);
    }
```

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments