Showing posts with label GUI. Show all posts
Showing posts with label GUI. Show all posts

Monday, June 27, 2011

GUI Button Tricks


/* String Content example */

function OnGUI () {
GUI.Label (Rect (0,0,100,50), "This is the text string for a Label Control");
}
To display an image, declare a Texture2D public variable, and pass the variable name as the content argument like this:
/* Texture2D Content example */

var controlTexture : Texture2D;

function OnGUI () {
GUI.Label (Rect (0,0,100,50), controlTexture);
}
Here is an example closer to a real-world scenario:
/* Button Content examples */

var icon : Texture2D;

function OnGUI () {
if (GUI.Button (Rect (10,10, 100, 50), icon)) {
print ("you clicked the icon");
}

if (GUI.Button (Rect (10,70, 100, 20), "This is text")) {
print ("you clicked the text button");
}
}
There is a third option which allows you to display images and text together in a GUI Control. You can provide a GUIContent object as the Content argument, and define the string and image to be displayed within the GUIContent.
/* Using GUIContent to display an image and a string */

var icon : Texture2D;

function OnGUI () {
GUI.Box (Rect (10,10,100,50), GUIContent("This is text", icon));
}
You can also define a Tooltip in the GUIContent, and display it elsewhere in the GUI when the mouse hovers over it.
/* Using GUIContent to display a tooltip */

function OnGUI () {
// This line feeds "This is the tooltip" into GUI.tooltip
GUI.Button (Rect (10,10,100,20), GUIContent ("Click me", "This is the tooltip"));
// This line reads and displays the contents of GUI.tooltip
GUI.Label (Rect (10,40,100,20), GUI.tooltip);
}
If you're daring you can also use GUIContent to display a string, an icon, and a tooltip!
/* Using GUIContent to display an image, a string, and a tooltip */

var icon : Texture2D;

function OnGUI () {
GUI.Button (Rect (10,10,100,20), GUIContent ("Click me", icon, "This is the tooltip"));
GUI.Label (Rect (10,40,100,20), GUI.tooltip);
}

Sunday, June 26, 2011

GUI Screen.width & Screen.height example



function OnGUI () {
GUI.Box (Rect (0,0,100,50), "Top-left");
GUI.Box (Rect (Screen.width - 100,0,100,50), "Top-right");
GUI.Box (Rect (0,Screen.height - 50,100,50), "Bottom-left");
GUI.Box (Rect (Screen.width - 100,Screen.height - 50,100,50), "Bottom-right");
}

Flashing button example


/* Flashing button example */

function OnGUI () {
if (Time.time % 2 < 1) {
if (GUI.Button (Rect (10,10,200,20), "Meet the flashing button")) {
print ("You clicked me!");
}
}
}
Here, GUI.Button() only gets called every other second, so the button will appear and disappear. Naturally, the user can only click it when the button is visible.
As you can see, you can use any desired logic to control when GUI Controls are displayed and functional. Now we will explore the details of each Control's declaration.

GUI Box with Two Action Buttons


/* Example level loader */

function OnGUI () {
// Make a background box
GUI.Box (Rect (10,10,100,90), "Loader Menu");

// Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
if (GUI.Button (Rect (20,40,80,20), "Level 1")) {
Application.LoadLevel (1);
}

// Make the second button.
if (GUI.Button (Rect (20,70,80,20), "Level 2")) {
Application.LoadLevel (2);
}
}
This example is a complete, functional level loader. If you copy/paste this script and attach it a GameObject, you'll see the following menu appear in when you enter Play Mode:


How do I create a menu system using Unity's GUI functions?


 need to follow the Unity GUI scripting guide:
For example, the following code will create a fully functional button from scratch:
function OnGUI () {
if (GUI.Button (Rect (10,10,150,100), "I am a button")) {
print ("You clicked the button!");
}
}

creating gui texture when object is destroyed

this is captured from Unity Answers
====================================================================

I am attempting to create a script that will destroy an object that a FPC collides with, then triggering a GUI texture. So far I have found a script to destroy an object based on colliders, is there anything i can add to trigger the GUI?
var other : GameObject;

function OnControllerColliderHit (hit : ControllerColliderHit){

if(hit.gameObject.tag == "Floor") {

Destroy(other);
print("Hey you destroyed me ");
}
}

Answer Algorithm================
======================================================================

var other : GameObject;
var destroyed: boolean;

function OnControllerColliderHit (hit : ControllerColliderHit){

if(hit.gameObject.tag == "Floor") {

Destroy(other);
print("Hey you destroyed me ");
destroyed=true;
}
}


function OnGUI(){
if (destroyed)
GUI.DrawTexture(Rect(10,10,60,60), aTexture);

}

Unity GUI Level Transition

This idea captured from one of the forums===========================================


create a space trading game and would like help with creating a script to allow the player to choose when to orbit a planet.


Main Algorithm


===========================================================================

var levelToLoad;
function OnTriggerEnter (other : Collider) {
if (other.gameObject.CompareTag("Player")) {
Application.LoadLevel("PlanetRotationTest");}}
This will load a new scene when the player approaches the trigger, however I would like instead for a button to appear on the GUI that the player can select when the wish to enter orbit. Any ideas?
=============================================================================
Algorithm for Answer
===================================================================================================================================================================
  1. Copy the scripts into separate files.
  2. Create a sphere. Remove the mesh renderer component. Set the collider to trigger, and scale it slightly larger than the planet. Then center it to the planet.
  3. Add the first script the the trigger, and the second to the player.
=============================================================================

Here's the script for the collider:
function OnTriggerEnter (other : Collider) {
if (other.CompareTag ("Player")) {
SendMessageUpwards ("SetClose");
}
}




function OnTriggerExit (other : Collider) {
if (other.CompareTag ("Player")) {
SendMessageUpwards ("SetFar");
}
}
Put this script on your player:
var close = false;

function SetClose () {
close = true;
}

function SetFar () {
close = false;
}

function OnGUI () {
if (close) {
if (GUI.Button (Rect (10,10,150,100), "I am a button")) {
Application.LoadLevel("PlanetRotationTest");
}
}
}
This will load that level when you click the button and you are near the planet. That's what the if statement is for and the trigger collider is for. Hope this helps!

Thursday, April 28, 2011

Flash Image GUI Lets You Easily Flash Custom ROMs, Kernel Images



 
Owning a android device, it’s common to do flashing stuff like ROM installations, Kernel installations, so on and so forth.
A dedicated flashing app is now available for few supported android devices. Developed by XDA member joeykrim, the free android app lets you easily flash image, kernel, or ROMs at ease.

The interface is very simple and there should be no problems in understanding it. The current version of Flash Image GUI only supports few devices including rooted Samsung Intercept, Transform, Moment, Acclaim, HTC Evo and HTC Shift android phones.

Support for more devices will be added as the developer gets more flash image binaries of the new devices. You may support his work or simply grab the latest version of the app from the XDA thread and simplify flashing.