- Home /
Question by
hakorcina · Feb 28, 2014 at 08:50 AM ·
camerainstantiateinvisible
Objects dont show on camera?
I used this script to instantiate objects:
using UnityEngine;
using System.Collections;
public class SpawnScript : MonoBehaviour {
public GameObject[] obj;
public float spawnMin = 1f;
public float spawnMax = 2f;
void Start () {
Spawn();
}
void Spawn()
{
Instantiate(obj[Random.Range (0, obj.GetLength(0))], transform.position, Quaternion.identity);
Invoke ("Spawn", Random.Range (spawnMin, spawnMax));
}
}
And it is working, but it only shows objects in editor. On camera it only shows first object(other are spawned, they have colliders, other objects can interact with them...but they are invisible).Why? Any help would be great since I actually don't have any idea why is this happening. Thx :)
Comment
Answer by CodeElemental · Feb 28, 2014 at 09:11 AM
From the code you posted, they appear to be spawned at the same position
transform.position
Try setting the position of the clone manually after instantiating.
GameObject spawnedObject = Instantiate(obj[Random.Range (0, obj.GetLength(0))], transform.position, Quaternion.identity);
spawnedObject.transform.position = <your position vector>;
Your answer
![](https://koobas.hobune.stream/wayback/20220613134957im_/https://answers.unity.com/themes/thub/images/avi.jpg)