- Home /
Question by
Stephanides · Nov 25, 2014 at 01:55 PM ·
objectspawnloop
Spawn Object
Hello im trying to spawn wall, i have start point and end point, i drag mouse this white mini wall and when i stop holding mouse button it should spawn wall object on left. When i make long mini wall i need to spawn more wall prefabs in road. But my code works bad, any advice ?
void VytvorStenu(){
float distance = Vector3.Distance (start.transform.position, end.transform.position);
if (!creating) {
Vector3 pozicia = start.transform.position;
//float distance = Vector3(start.transform.position, end.transform.position);
for(float x = 17; x < distance; x+=17){
plocik = (GameObject)Instantiate (plot, pozicia, Quaternion.identity);
plocik.transform.LookAt (end.transform.position);
pozicia = start.transform.position + new Vector3(17f,0,0);
Destroy (stena);}
Destroy(stena);
}
}
obrayok.png
(327.3 kB)
Comment
Best Answer
Answer by Stephanides · Nov 25, 2014 at 02:10 PM
Guys thanks for reply i solved it, i need to get end - start and then normalize and work with normalize vector, thanks all
Your answer
![](https://koobas.hobune.stream/wayback/20220613172406im_/https://answers.unity.com/themes/thub/images/avi.jpg)