Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class MouseManager : MonoBehaviour {
- GameObject obj;
- GameObject prevObj = null;
- public GameObject menu;
- public Text txt_nomPays;
- public Text txt_population;
- public Text txt_nbSieges;
- public Dropdown cbo_Partis;
- public Text txt_popularite;
- public Text txt_nbAdh;
- public Text txt_nbMil;
- public Text txt_bord;
- private Color rouge = new Color32(223,223,223,255);
- // Use this for initialization
- void Start () {
- }
- // Update is called once per frame
- void Update () {
- if(Input.GetMouseButtonDown(0)) {
- //La position est par rapport à l'écran et doit être converti en worldspace
- Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
- //on enlève la 3e coordonnée : z
- Vector2 mousePos2D = new Vector2(mousePos.x, mousePos.y);
- //récupère le gameObject cliqué
- RaycastHit2D hit = Physics2D.Raycast(mousePos2D, Vector2.zero);
- obj = hit.transform.gameObject;
- if(hit.collider != null && prevObj != null) {
- prevObj.GetComponent<Renderer>().material.color = rouge;
- //si l'obj est différent de celui précédemment cliqué
- if(obj != prevObj) {
- obj.GetComponent<Renderer>().material.color = Color.blue;
- recupInfo();
- } else {
- obj.GetComponent<Renderer>().material.color = rouge;
- menu.SetActive(false);
- }
- prevObj = obj;
- } else {
- obj.GetComponent<Renderer>().material.color = Color.blue;
- recupInfo();
- prevObj = obj;
- }
- }
- }
- void recupInfo() {
- //int nbSieges = GService.GetNombreSiege(obj.Name);
- menu.SetActive(true);
- string nomPays = obj.GetComponent<PaysView>().Nom;
- Debug.Log(nomPays);
- txt_nomPays = GetComponent<Text>();
- txt_nomPays.text = nomPays;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement