#Threading so as to not take up space

1 messages · Page 1 of 1 (latest)

idle python
#
    public void GenerateTree(float x, float y)
    {
        PlaceTile(log1, x, y);
    }

    public void PlaceTile(Sprite tileSprite, float x, float y)
    {
        GameObject newTile = new GameObject();
        newTile.transform.parent = this.transform;
        newTile.AddComponent<SpriteRenderer>();
        newTile.GetComponent<SpriteRenderer>().sprite = tileSprite;
        newTile.name = tileSprite.name;
        newTile.transform.position = new Vector2(x + 0.5f, y + 0.5f);

        worldTiles.Add(newTile.transform.position - (Vector3.one * 0.5f));
    }
}```snippet of what I have so far
#

Right now I'm using the GenTree function to create a base tile with one texture, some middle logs, and a top

#

I'm unfamiliar with looping in C# though :/

opal adder
#

for loop

idle python
#

Spoonfeed?

opal adder
#

and create a different random number each time between a range

idle python
#

So in a for loop

#

StackO example for (int i = 0; i < count; i++)

opal adder
#

yes exactly

idle python
#

As I understand this, set i to 0

#

while i < count, count being a variable

#

run the loop

#

and i++ is add one to i for each loop?

opal adder
#

yes its the amount of times it does it

#

the condition

#

yes

#

i++ just adds 1

#

its the same as i+=1

idle python
#

So why does i++ add 1 to the loop every loop, but int i = 0 doesn't reset the variable every loop??

#

Semantics?

opal adder
#

it doesnt go through that part every time

#

it just acts based on them

#

first is the starting point then second is the condition and third is what it does to the starting point

idle python
#

🇮 🇨

opal adder
#

if count would be 10 and you had print(i) in the for loop it would print 1 2 3 4 5 6 7 8 9 10

#

do you get it

idle python
#

yea yea

#

I've worked with Minecrafts Skript before so I have like super basic entry level how to use certain functions, but I am super new

#
    public void GenerateTree(float x, float y)
    {
        count = Random.Range(0, 5);
        PlaceTile(log1, x, y);
        for (int i = 0; i < count; i++)
        {
            PlaceTile(log2, x, y+i);
        }
        PlaceTile(log3, x, y+i+1);
    }```
#

So this, I'm getting some hierarchy errors

opal adder
#

remember that the Update() function is also a loop

#

every frame it goes through it

#

and you could have a variable change everytime it goes through it

idle python
idle python
#
    public void GenerateTree(float x, float y)
    {
        treeSize = Random.Range(2, 5);
        PlaceTile(logBase, x, y);
        for (int i = 0; i < treeSize; i++)
        {
            PlaceTile(logMid, x, y+i);
        }
        PlaceTile(logTop, x, y+treeSize+1);
    }``` no errors just kills the world generator as soon as I try to place a tree
#

Heyyy I got it

#

For some reason not assigning a texture kills it

opal adder
#

💯