Code : Tout sélectionner
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Window : MonoBehaviour {
public string name;
public GameObject newWindow;
public GameObject close_button;
public Window()
{
}
public GameObject open()
{
/*
1.On instancie la nouvelle fenêtre.
2.On recherche le canvas sur la scène.
3.On place la fênêtre en enfant du canvas.
4.On place la fênetre au centre du canvas.
*/
newWindow = Instantiate(Resources.Load("Prefab/Repaire/Window_" + name, typeof(GameObject))) as GameObject;
newWindow.name = "Window_" + name;
GameObject canvas = GameObject.Find ("Canvas_Repaire");
newWindow.transform.parent = canvas.transform;
newWindow.GetComponent<RectTransform> ().anchoredPosition = new Vector2 (0, 0);
close_button = newWindow.transform.Find ("fenetre-fond/top-window/close-btn").gameObject;
Debug.Log (close_button.name);
close_button.GetComponent<Button> ().onClick.AddListener(() => close());
return newWindow;
}
public void close()
{
Debug.Log ("Test");
Destroy (this);
}
}