using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class z_minimap : MonoBehaviour
{
public GameObject lists;
public Image thisimage;
public Sprite map;
public Texture2D texture;
void Start()
{
lists = GameObject.Find("lists");
//setup minimap sprite texture
texture = new Texture2D(250, 250);
texture.filterMode = FilterMode.Point;
map = Sprite.Create(texture, new Rect(0f, 0f, texture.width, texture.width), new Vector2(0.5f, 0.5f), 100f);
thisimage.sprite = map;
}
void Update()
{
draw();
}
void draw()
{
List <GameObject> list = lists.GetComponent<lists>().player;
foreach(GameObject unit in list)
{
int x = Mathf.RoundToInt(unit.transform.position.x + 50f * 2.5f);
int y = Mathf.RoundToInt(unit.transform.position.z + 50f * 2.5f);
texture.SetPixel(x, y, Color.black);
}
texture.Apply();
}
}
I’m trying to add a minimap of sorts to my game. The minimap is just a 250x250 button anchored to the bottom-left. It has no sprite or material. At the start I create a blank 250x250 texture, set the filter mode to point, and use the texture to create a sprite to apply to the button’s Image.sprite.
I then iterate through a list of player units at draw(). The game world is 100x100 sized, between -50,-50 and 50,50. So i take the unit’s position x/y and convert that to between 0 and 250, and I make that pixel black for the texture.
It works, but the resolution for the sprite texture of the minimap seems to be displaying as 36x36 ro something really small, not 250x250. That is, when I change an individual pixel for the texture, it’s appears much bigger than it should be. Each pixel I set should be 1x1, that is what a pixel is afterall, but they are something like 8x8.

I tried setting texture.mipMapBias to different values but it looks the same. I don’t know what to do. This is my first time creating a sprite/texture via SetPixel, and it doesn’t display any of the properties in the inspector panel for me to play around with. Visually, this Huge Texture Not Keeping Resolution - Questions & Answers - Unity Discussions seems like a similar issue, the texture is displaying much blockier than it should be, so I’m thinking perhaps the max resolution need to be set when you create a texture/sprite via code.
Also draw() is just helping me learn how this is done, so the fact it’s not clearing/refreshing old positions is not an issue for now. Any help would be appreciated, thanks.

