Unity Web Player. Install now!

Your browser does not support the Unity Web Player. Want to save the test for later? Add it to a collection.

Add Test To Collection

var matImg:Material;
var t2img:Texture2D;
var sectorImg:Rect;
var t2sprites:Texture2D;
var iTilesX:int;
var iTilesY:int;
var sectorSpr:Rect;



var mouse : MouseLook;



private var iTileX=1;
private var iTileY=1;



private var botones:Rect[];



function Start() {
botones = new Rect[iTilesX*iTilesY];
var bx=10.0;
var by=10.0;
var mx=100.0;
var my=20.0;
for (var boton in botones) {
boton=Rect(bx,by,mx,my);
by+=5.0+my;
}
matImg.mainTexture = t2img;
sectorImg.y=t2img.height-(sectorImg.y+sectorSpr.height);
}



function Update () {
if (Input.GetButtonDown("Fire2")) mouse.enabled=true;
if (Input.GetButtonUp("Fire2")) mouse.enabled=false;
}



function modificarImg (spr:int) {
var i=spr;
iTileX=1;
iTileY=1;
while (i>1) {
if (iTileX<=iTilesX) iTileY++;
if (iTileY>iTilesY) {
iTileY=1;
iTileX++;
}
i--;
}
sectorSpr.x=(iTileX*sectorSpr.width)-sectorSpr.width;
sectorSpr.y=(iTileY*sectorSpr.height)-sectorSpr.height;
sectorSpr.y=t2sprites.height-(sectorSpr.y+sectorSpr.height);
var pixelsSprite=t2sprites.GetPixels(sectorSpr.x,sectorSpr.y,sectorSpr.width,sectorSpr.height,0);

t2img.SetPixels (sectorImg.x,sectorImg.y,sectorImg.width,sectorImg.height, pixelsSprite, 0);
t2img.Apply( false );
Debug.Log("Sprite #"+spr+" ("+iTileX+", "+iTileY+")");
}



function OnGUI() {
var i=1;
for (var boton in botones) {
if (GUI.Button(boton, "sprite "+i)) {
modificarImg (i);
}
i++;
}
}

More information

Published1 year ago
StatusPrototype
CategoryOther
PlatformsUnity
Authorestantaya
Tagssetpixels, ubito, unitoy, unity