Hi
I want to spawn my prefab on a random x axis point inside the camera. But my problem is, only half of the prefab is inside the camera. Here are some photos you can understand.
My camera is vertical by the way
Also my code:
public GameObject enemyObject;
float spawntime = 2f;
// Use this for initialization
void Start () {
Invoke ("spawnEnemy", spawntime);
}
// Update is called once per frame
void Update () {
}
void spawnEnemy()
{
Vector2 min = Camera.main.ViewportToWorldPoint (new Vector2 (1,1));
Vector2 max = Camera.main.ViewportToWorldPoint (new Vector2 (0,0));
GameObject enemy = (GameObject)Instantiate (enemyObject);
enemy.transform.position = new Vector2 (Random.Range (min.x, max .x), max.y);
}
}
I could not find a solution on the internet and I really don’t know what to do. Please help
,