Share a tool class that uses Ongui to print debug information on your phone

Source: Internet
Author: User

When the game is released to the phone debugging sometimes need to print some information on the screen, I wrote a Gadget class, share it, with the Ongui, very simple, directly on the code


Using Unityengine;

Using System.Collections;

Using System.Collections.Generic;


public class Onguidebug:monobehaviour {


public static Onguidebug Instance;


public int FontSize = 40;

public int labelheight = 40;

int labelpos_y = 0;

Message list

static list<string> msglist = new list<string> ();

Guistyle style = null;


void Awake () {

style = new Guistyle ();

Style.fontsize = fontSize;

Style.normal.textColor = color.red;


Instance = this;

Dontdestroyonload (Gameobject);

}


public static void Addmsg (String msg)

{

if (!msglist.contains (msg))

Msglist.add (msg);

}


void Ongui ()

{

Labelpos_y = 10;

for (int i = 0; i < Msglist.count; i++)

{

Gui. Label (New Rect (Ten, Labelpos_y, Labelheight, msglist[i], style);

Labelpos_y + = Labelheight;

}

if (labelpos_y >= screen.height)

{

if (Msglist.count > 0)

Msglist.removeat (0);

}

}


void Start ()

{

Invokerepeating ("Testmsg", 1, 1);

}


int counter = 0;

void Testmsg ()

{

Msglist.add ("Test" + (++counter). ToString ());

}


}


In fact, if you use a text field with a scroll bar or scroll view what might be better to use, you can try it.

Share a tool class that uses Ongui to print debug information on your phone

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.