- public Texture2D center;
- void Start() {
- ...
- center = (Texture2D) Resources.Load("center", typeof(Texture2D)); // Assigns a texture named "center.png" to a Texture2D(center).
- ...
- }
- void OnGUI() {
- ...
- if (GUI.Button (new Rect (850, 570, 32, 32), new GUIContent(center))) {
- ...
- }
- ...
- }
Showing posts with label Unity3d. Show all posts
Showing posts with label Unity3d. Show all posts
Dec 12, 2013
[Unity3d] GUI Button Image
[Unity3d] Background Image
You're almost there, with the 2nd camera approach. Here's how to do it:
Voila, this should give you your GUI Texture rendered by your background camera, behind everything else rendered by your main camera. And for any other additional cameras (eg, other camera angles) that you want to use, just repeat the last two steps on them.
Original Text:
|
Oct 8, 2013
[Unity3d] How to access variables from other scripts
This is based on Unity 4.1. It might be different depending on Unity versions.
Suppose that you want to access aaa.js from bbb.js.
aaa.js
var nSource : int; // It doesn`t have to be static, but private is not allowed here.
bbb.js
var src : aaa;
function Start ()
{
{
src = FindObjectOfType(aaa);
}
Usage:
function customFunction()
{
var a = aaa.nSource;
}
[Unity3d] How to convert 3d coords to 2d GUI position
You can use WorldToScreenPoint function.
var screenPos : Vector3 = GameObject.FindWithTag("MainCamera").camera.WorldToScreenPoint( transform.position);
var screenPos : Vector3 = GameObject.FindWithTag("MainCamera").camera.WorldToScreenPoint( transform.position);
[Unity3d] C++ dll for iPhone and XBox 360
#if UNITY_IPHONE || UNITY_XBOX360 // On iOS and Xbox 360 plugins are statically linked into // the executable, so we have to use __Internal as the // library name. [DllImport ("__Internal")] #else // Other platforms load plugins dynamically, so pass the name // of the plugin's dynamic library. [DllImport ("PluginName")] #endif
iOS and X-Box use dll as a static library. So, you should use "__internal" when importing.
[Unity3d] How to use C++ dll in Unity3d
1. Make CLI Class library project in Visual Studio.

2. Delete all files except main cpp file. You don`t need other auto created files.

3. Write down the codes you need like this.

4. Drag and drop the dll file to Unity Assets/Plugins. It is recommended that you use release mode rather than debug mode while building the project.
(Make sure you drag and drop to Plugins folder. Other folders may not work or cause errors.)

5. Create a C# script and attach it to a game object. Write code as below.

Then you will have value of '1102' in integer variable "nRet".
[Unity3d] How to change mouse cursor.
1. Put the png file in "Assets/Textures/UI/Resources "
2. Write the code as below.

Then you will see the mouse cursor changed if the mouse button is down.
Have fun.
[Unity3d] How to pop up web browser.
Application.ExternalEval("window.open('http://www.google.com','_blank')");
Caution: Popup prevention option of the web browser must be turned off.
Caution: Popup prevention option of the web browser must be turned off.
[Unity3d] How to send message from web browser to Unity Web Player.
It is especially useful, when you start and initialize your unity web player.
First, you need to write java script in the web side like this.
document.getElementById("UnityContent").SendMessage("UnityObject", "UnityFunction", "argument");
If you have Unity Object, then it will be more simple like this
var u = new UnityObject2(config) ;
u.getUnity().SendMessage("UnityObject", "UnityFunction", "argument");
Then make an empty game object in unity editor. In this case, "UnityObject" is the name of the game object. Add a javascript to the object and write as below.
function UnityFunction(param : string)
{
var ret = param;
}
Then your Unity Web Player will have the message from the web server.
Caution :
While loading, Unity Web Player can not receive any messages. So, is is possible that the message is ignored. To prevent this, ask the web server to send message after completing loading like this.
function Start ()
{
Application.ExternalCall("GetMessage");
}
Application.ExternalCall("GetMessage");
}
GetMessage is a user defined function name. And write in your web server as below.
function GetMessage()
{
u.getUnity().SendMessage("IdObject", "PutPlayerId", "serfefer");
}
{
u.getUnity().SendMessage("IdObject", "PutPlayerId", "serfefer");
}
Then, web server will send a message after Unity Web Player is completely loaded, and no message will be lost.
[Unity3d] How to change scenes without interrupting or pausing the game.
GetStreamProgressForLevel returns progression of the loading.
You can show the progress bar using this function.
If you want to change scenes without interruption, do like this.
if(Application.GetStreamProgressForLevel("mainui") == 1)
{
Application.LoadLevel("mainui");
}
You can show the progress bar using this function.
If you want to change scenes without interruption, do like this.
if(Application.GetStreamProgressForLevel("mainui") == 1)
{
Application.LoadLevel("mainui");
}
[Unity3d] How to find camera
If you can check the tag of the game object, it is as simple as below.
GameObject.FindWithTag("MainCamera").camera
GameObject.FindWithTag("MainCamera").camera
Subscribe to:
Posts (Atom)