-1

I created a unity application for desktop and mobile platforms. There is a map on top-left corner of the screen. I draw circle on this map each frame. The position of the circle changes at runtime anytime.

To do for this task, I draw circle on texture and draw this texture. This code works on emulator but not android phone or tablet. I don't see any circle on the map.

My code is here :

TextAsset imageAsset; // .png changes to .png.bytes. And the file dragged to this variable on inspector.

Start () {
  texture.LoadImage(imageAsset.bytes); 
}

void OnGUI () {

  Circle(texture, x, y, Color.red);

  if (Event.current.type.Equals(EventType.Repaint))
  {
    Graphics.DrawTexture(new Rect(..), texture);
  }
}

Some people say deprecated OnGUI. But if I create a button in OnGUI, it is displayed at runtime on android.

I tried another solution. I create a 3d plane object on my scene, and drag .png file as texture. But I don't change this texture using Texture2D variable that is drawed circle.

zakjma
  • 2,030
  • 12
  • 40
  • 81

2 Answers2

0

You should use sprites, and why did you use the OnGui Function instead of the Update ?

Maybe get a look on the asset store : 2DToolkit

CrymX
  • 39
  • 2
  • `if (Event.current.type.Equals(EventType.Repaint))`returns only OnGUI function, not Update. I will try to use sprite. – zakjma Apr 22 '16 at 11:26
0

What is the resolution of your device and your image?

I'm asking this because you should consider change of resolutions between your computer's screen and yours device.

As you can see here your rect values must be in pixels.

I recommend you to use raw image for loading your texture, a Canvas for handling drawing and RectTransform for controlling your circle position instead.

These components have many functionalities to deal with this resolutions problems that may happen.

Ronaldo Felipe
  • 402
  • 2
  • 13