Connexion




Poster un nouveau sujet Répondre au sujet  [ 1 message ] 
Auteur Message
 Sujet du message: Unity3d Script (on trigger GUI)
UNREAD_POSTPosté: Ven Avr 01, 2011 6:31 am 
NooFondateur
Avatar de l’utilisateur
Inscription: Mar Jan 09, 2007 3:21 am
Messages: 1166
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
    }


 Hors ligne
 

Afficher les messages postés depuis:  Trier par  

Poster un nouveau sujet Répondre au sujet  [ 1 message ] 


Qui est en ligne

Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 3 invités

Panel

Haut Vous ne pouvez pas poster de nouveaux sujets
Vous ne pouvez pas répondre aux sujets
Vous ne pouvez pas éditer vos messages
Vous ne pouvez pas supprimer vos messages
Rechercher:
Aller à:  
 cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Traduction par: phpBB-fr.com
Dizayn Ercan Koc