trouvé ici
http://answers.unity3d.com/questions/32 ... f-a-button
Code : Tout sélectionner
//attach this script to your first person controller
var targetObj : GameObject;//drag your target into this slot in the editor
var proximity : float = 3;//change trigger proximity here or in editor
private var buttonOn : boolean;
private var windowOn : boolean;
private var windowRect : Rect = Rect (150, 150, 120, 50);//window parameters
function Update() {
var dist = Vector3.Distance(targetObj.transform.position, transform.position);
//check whether you are within target proximity
if (dist < proximity) {
buttonOn = true;
}
else {
buttonOn = false;
}
}
function OnGUI () {
if (buttonOn ==true) {
if (GUI.Button (Rect (25, 25, 100, 30), "WindowOn")) {
windowOn = true;
}
if (GUI.Button (Rect (25, 100, 100, 30), "WindowOff")) {
windowOn = false;
}
if (windowOn == true) {
windowRect = GUI.Window (0, windowRect, WindowFunction, "My Window");
}
}
//take this "else-statement out if you want the activation of the window to be remembered, even if you leave the proximity of the object
else {
windowOn = false;
}
}
function WindowFunction (windowID : int) {
// Draw any Controls inside the window here
}