I am currently trying to put a sprite in the lower left corner of the screen.
I am doing to following to put the sprite in place:
Vector3 bottomLeft = new Vector3 (-Screen.width, -Screen.height, 1.0f);
Camera cam = GameObject.Find ("Camera").GetComponent<Camera> ();
transform.position = cam.ScreenToViewportPoint (bottomLeft);
The first image I attached is what the screen looks like when I press play
The second image is the screen. In the lower left you can see the sprite I am trying to draw.
I have no idea how to get that image to appear on camera, when I change the points a bit manually it shows up on screen. Also sometimes when I make the screen bigger it comes into view but not directly in the very lower left.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Map : MonoBehaviour {
public int rows;
public int cols;
private ArrayList _map;
// Use this for initialization
void Start () {
_map = new ArrayList (rows);
for (int y = 0; y < rows; y++) {
ArrayList row = new ArrayList(cols);
for (int x = 0; x < cols; x++) {
GameObject tile = (GameObject)Instantiate(Resources.Load("Prefabs/Tile"));
tile.transform.parent = transform;
_map.Add (tile);
}
}
}
// Update is called once per frame
void Update () {
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Tile : MonoBehaviour {
private static Sprite[] _sprites;
private SpriteRenderer _renderer;
private bool _needUpdate = true;
public TileSpriteEnum tile;
// Use this for initialization
public void Start () {
Vector3 bottomLeft = new Vector3 (-Screen.width, -Screen.height, 1.0f);
Camera cam = GameObject.Find ("Camera").GetComponent<Camera> ();
transform.position = cam.ScreenToViewportPoint (bottomLeft);
_renderer = GetComponent<SpriteRenderer> ();
System.Array values = System.Enum.GetValues (typeof(TileSpriteEnum));
System.Random random = new System.Random ();
tile = (TileSpriteEnum)values.GetValue(random.Next(values.Length));
if (_sprites == null) {
_sprites = Resources.LoadAll<Sprite> ("Tiles_Basic");
}
}
// Update is called once per frame
public void Update () {
if (_needUpdate) {
if (_sprites != null) {
_renderer.sprite = _sprites [(int)tile];
_needUpdate = false;
}
}
}
}

