multiple draw calls on same Texture2D with independent X and Y coordinates

Hello all!

I’m making a fishing game, however i’ve been stuck on my fishfinder code.

Im trying to make something like this: [PiranhaMax 180 - Demo - YouTube][1]

I shoot a ray from bottom of my boat to track the distance from it to Terrain = depth.

Then i use GUI.DrawTexture to draw one “pixel” to the GUI. This shall be the bottom of the lake, the distance from the top of the screen to the texture is equal with the distance from boat to the terrain… However i cant find way to draw multiple textures with the same texture and move them with independent x and y positions, so the screen actually “updates”.

Here’s my code

var hit : RaycastHit;
var echoPixel : Texture2D;
var echoHit : RaycastHit;


var pixelPosX = 210;
var pixelPosY = 200;


var fishDepth : float = 0.0f;

var echoWindow : Rect = Rect(40,250,220,270);

function Start () {

}

function Update () {

var EchoSounder = gameObject.Find("EchoSounder").transform;

var bottom = transform.position - Vector3(0,1,0); // define the boat's bottom

Debug.DrawRay(bottom,-transform.up * 100, Color.red); // debug depth tracker

	if (Physics.Raycast(bottom,-transform.up,hit, 100)){ // depth tracking
		if (hit.transform.name == "Terrain"){
			depth = hit.distance;
		}
	
	}	
	
	Debug.DrawRay(EchoSounder.position,-transform.up * 100, Color.grey); // debug fish tracker
	
		if (Physics.Raycast(EchoSounder.position,-transform.up,echoHit, 100)){ // fish tracking
	
		if (echoHit.transform.tag == "Fish"){ // if fish found, set fishdepth
			fishDepth = echoHit.distance;
	
		}
	
	}	


}

function OnGUI(){

echoWindow = GUI.Window(0, echoWindow, newWindow,"Fishfinder");

}

function newWindow(windowID: int){

var pixMax = 250; // total vertical pixels of the screen
var maxDepth = 20; // maxium depth 20 meters


pixelPosY = depth / maxDepth * pixMax; // pixelPosY = convert the distance from the boat to the bottom to the screen. 

GUI.DragWindow (Rect (0,0,10000,10000));


GUI.Label(Rect(10,20,100,20),depth.ToString("f1")+ " Meters"); // display depth
GUI.Label(Rect(10,40,100,20),"Fish at: "+ fishDepth.ToString("f1")+ " Meters"); // temporal fish display


movePixel();



if (pixelPosX < 11) // move the pixel to the begin of the screen
	pixelPosX = 210;


}

function movePixel()
{
var posX = pixelPosX;
var posY = pixelPosY;
for(var i = 210;i > 10;i--)
{
GUI.DrawTexture(Rect(posX,posY,1,250), echoPixel); // draw a pixel
posX = posX - 1; // move the pixel
}

If you have something to suggest i’ll appreciate that.
Thank you

1 Answer

1

If you use planes with textures, you’ll have access to materials (GUITextures don’t use them.) In the material you can then set offset and tiling however you like. For examples, offset=0.5 and tiling=0.25 will display the 3rd quarter of the texture; offset=0.43 tiling=0.01 will display the 44th percent of the image.

You can do it by hand, just to test, but Materials are the one place where the “click next to and slide” trick doesn’t work.