A downloadable game for Windows

Download NowName your own price

Controls: f to enter a car.

Player and npc appearances can be know randomly generated! The shirt uses a material .. a texture atlas of 16 shirt textures and this following code allows to randomly choose a texture from the atlas to apply to the shirt

using UnityEngine;

public class Shirt : MonoBehaviour

{

    public Texture2D atlas;

    public int tilesX = 1; // Number of columns in the atlas

    public int tilesY = 1; // Number of rows in the atlas

    private void Start()

    {

        ChangeTexture();

    }

    [ContextMenu("ChangeTexture")]

    public void ChangeTexture()

    {

        if (atlas == null) return;

        Renderer rend = GetComponent<Renderer>();

        MaterialPropertyBlock block = new MaterialPropertyBlock();

        rend.GetPropertyBlock(block);

        // Auto tile size

        float tileWidth = 1f / tilesX;

        float tileHeight = 1f / tilesY;

        // Random index

        int totalTextures = tilesX * tilesY;

        int index = Random.Range(0, totalTextures);

        int xIndex = index % tilesX;

        int yIndex = index / tilesX;

        float offsetX = xIndex * tileWidth;

        float offsetY = 1f - tileHeight - yIndex * tileHeight;

        block.SetVector("_MainTex_ST", new Vector4(tileWidth, tileHeight, offsetX, offsetY));

        rend.SetPropertyBlock(block);

    }

}

the textureatlas is 1024*1024 pixels and each shirt texture in it is  256*256. The hat is randomly chosen by enable a random hat that is child of armature => head .

This a unique mechanism very optimized (using only one material = texture atlas). 

Also the cars are working perfectly wich is awesome!!!

Download

Download NowName your own price

Click download now to get access to the following files:

TestingGame.zip 20 MB

Leave a comment

Log in with itch.io to leave a comment.