- Home /
Instantiate Clones Itself - Rather than Prefab
I don't really understand what I'm doing wrong here - might just need a fresh pair of eyes to look for me.
I'm building a 'wall building' system for my game - where you place a wall post down (post A), and if you place another wall post (post B) inline with each other - a load of other wall posts will be Instantiated between post A and post B.
The problem I'm having is that my wall post is a prefab. When that post 'sees' another post, it will Instantiate that wall prefab. The problem is, is that it seems to clone itself, and not use a fresh prefab. I know this because all my variables within my scripts are the same (even though they are blank/default in my prefab).
This script 'looks' on the left side of the wall - to see if a raycast as hit any other posts
var cube : GameObject;
var c : WallDefense;
var wall : GameObject;
for(var pLeft = 1; pLeft < leftPoints.Count; pLeft++){
cube = Instantiate(wall, transform.position, transform.rotation);
cube.transform.position = leftPoints[pLeft].position;
cube.transform.position.y = 0;
cube.transform.name = "Defense_Wall";
c = cube.GetComponent(WallDefense);
c.US = US;
c.wall = wall;
}
'Wall' is the prefab of my ... Wall. Although, when running the game - if I select the variable within the Inspector, it highlights itself in the scene, instead of the prefab in the prefab folder.