Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Kajo · Apr 28, 2013 at 09:56 AM · multipledrawcallsgui.drawtexture

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: [http://www.youtube.com/watch?v=Bieo9wRABtk][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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Owen-Reynolds · Apr 28, 2013 at 03:22 PM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Reduce Draw call for Multiple GUI Textures with same Texture 1 Answer

Multiple cameras increasing draw call count immensely 1 Answer

Game States, communication through scenes and objects 1 Answer

Multiple animations in the same FBXfile? 9 Answers

Multiple triggers on one object 8 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges