- Home /
Question by
Ajkidoo · Mar 29, 2018 at 04:30 PM ·
instantiatescript.prefabs
Something wrong with my project
Hi, I need help with my project because something went wrong and I dont know why. I wanted one of my scripts to choose one of 2 ''paths'' i created for objects called "Tiles"
public Transform Tile1;
public Transform Tile2;
public Transform Tile3;
void Start ()
{
if (Random.value <= 0.5) {
Tile1.position = new Vector3 (3, 2.136f, -4.413f);
Tile2.position = new Vector3 (3.481f, 2.136f, -3.697f);
Tile3.position = new Vector3 (3.979f, 2.136f, -2.976f);
}
else
{
Tile1.position = new Vector3 (3.482f, 2.136f, -4.413f);
Tile2.position = new Vector3 (2.838f, 2.136f, -3.697f);
Tile3.position = new Vector3 (4.319f, 2.136f, -4.42f);
}
}
and then replace those objects with one of three prefabs
(that script is attached to each "Tile" object)
public GameObject myPrefab1;
public GameObject myPrefab2;
public GameObject myPrefab3;
// Use this for initialization
void Start () {
if (Random.value <= 0.33) {
Instantiate (myPrefab1, transform.position, Quaternion.identity);
}
else if (Random.value <= 0.33) {
Instantiate (myPrefab2, transform.position, Quaternion.identity);
}
else {
Instantiate (myPrefab3, transform.position, Quaternion.identity);
}
}
I wanted to make a simple generator-like thing which i can easily control. The problem is when i run my game everything works correctly except when one of those objects become myPrefab1. It appears in game but it has different coordinates than "Tile" object. I dunno what i messed up. Can anyone tell me whats wrong ? Thanks in advance. (Sorry, english isn't my native language, so it can hurt your eyes :~)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612155623im_/https://answers.unity.com/themes/thub/images/avi.jpg)