In my game, there is a maze, which has its walls generated by several types of points. In the top row, there are points that I call "type A" point - they only generate walls vertically (downward). "Type B" points have only horizontal (sideways) walls, and "type C" points generate both horizontal and vertical walls. All "A, B and C" points also generate items
because of this, I am using "shared" functions that are referenced on another script, in order to boost efficiency and so that I don't have identical code for the functions of generation on these points, as they all generate items the same way, and where applicable, generate horizontal and vertical walls in exactly the same way.
The issue here is, that I have a central script, that, within the scripts for "A, B and C", is referenced (public void function). the referencing works perfectly well.
however all the vertical walls generate on exactly the same point "A", (of which is first in terms of it's position in the row, and additionally first in the hierarchy); instead of all the different point "A"'s, meaning the rest of the point "A"'s are blank.
My function is "GenVwall", short for "Generate Vertical Wall", located in the central script:
public void GenVwall () {
GameObject objV;
//Decide the probability of there being a tile
float lvlF = Mathf.Log10(gameManagerS.lvlNum);
float pointF = 38.2f + (9.8f * (lvlF + 1));
float decideV = Random.Range(0, 100);
//Spawn different wall types (vertically)
if (decideV < pointF) {
int vWall = Random.Range (0, 40);
if (vWall <= 24) {
objV = Instantiate (Resources.Load ("tiles/wallReg"), new Vector2 (transform.position.x, (transform.position.y - 0.417f)), transform.rotation) as GameObject;
} else if (vWall > 24 && vWall <= 26) {
objV = Instantiate (Resources.Load ("tiles/wallSpiked"), new Vector2 (transform.position.x, (transform.position.y - 0.417f)), transform.rotation) as GameObject;
} else if (vWall > 26 && vWall <= 31) {
objV = Instantiate (Resources.Load ("tiles/wallBreak"), new Vector2 (transform.position.x, (transform.position.y - 0.417f)), transform.rotation) as GameObject;
} else if (vWall > 31 && vWall <= 35) {
objV = Instantiate (Resources.Load ("tiles/wallHalf"), new Vector2 (transform.position.x, (transform.position.y - 0.417f)), transform.rotation) as GameObject;
} else if (vWall > 35 && vWall <= 38) {
objV = Instantiate (Resources.Load ("tiles/wallGate"), new Vector2 (transform.position.x, (transform.position.y - 0.417f)), transform.rotation) as GameObject;
} else if (vWall > 38) {
objV = Instantiate (Resources.Load ("tiles/wallExplode"), new Vector2 (transform.position.x, (transform.position.y - 0.417f)), transform.rotation) as GameObject;
}
}
}
and the referencing of the public void function, located within the "A" point script, is:
GameObject tempObj = GameObject.Find("genPointA");
genPointS = tempObj.GetComponent<GenPointS>();
genPointS.GenVwall();
Now, I believe the issue lies within the fact i use transform.position, and it's referring to the position of the first "point A" in the hierarchy.
Now, I'd like to know,
Is there a better way to make use of these functions? as I can't consider it too efficient to have the same function copy-pasted into the individual scripts for point "A, B and C".