noocrypte.net
http://noozone.free.fr/noocrypte/

Unity3d Script (on trigger GUI)
http://noozone.free.fr/noocrypte/viewtopic.php?f=47&t=895
Page 1 sur 1

Auteur:  yann.minh [ Ven Avr 01, 2011 6:31 am ]
Sujet du message:  Unity3d Script (on trigger GUI)

Script pour afficher une fenetre GUI a l'approche d'un objet
trouvé ici
http://answers.unity3d.com/questions/32 ... f-a-button




Code:
//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
    }

Page 1 sur 1 Heures au format UTC [ Heure d’été ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/