Advertisement
Guest User

Untitled

a guest
Oct 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class MouseManager : MonoBehaviour {
  7.  
  8. GameObject obj;
  9. GameObject prevObj = null;
  10. public GameObject menu;
  11. public Text txt_nomPays;
  12. public Text txt_population;
  13. public Text txt_nbSieges;
  14. public Dropdown cbo_Partis;
  15. public Text txt_popularite;
  16. public Text txt_nbAdh;
  17. public Text txt_nbMil;
  18. public Text txt_bord;
  19.  
  20. private Color rouge = new Color32(223,223,223,255);
  21.  
  22. // Use this for initialization
  23. void Start () {
  24.  
  25. }
  26.  
  27. // Update is called once per frame
  28. void Update () {
  29. if(Input.GetMouseButtonDown(0)) {
  30. //La position est par rapport à l'écran et doit être converti en worldspace
  31. Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
  32. //on enlève la 3e coordonnée : z
  33. Vector2 mousePos2D = new Vector2(mousePos.x, mousePos.y);
  34. //récupère le gameObject cliqué
  35. RaycastHit2D hit = Physics2D.Raycast(mousePos2D, Vector2.zero);
  36. obj = hit.transform.gameObject;
  37.  
  38. if(hit.collider != null && prevObj != null) {
  39. prevObj.GetComponent<Renderer>().material.color = rouge;
  40.  
  41. //si l'obj est différent de celui précédemment cliqué
  42. if(obj != prevObj) {
  43. obj.GetComponent<Renderer>().material.color = Color.blue;
  44. recupInfo();
  45. } else {
  46. obj.GetComponent<Renderer>().material.color = rouge;
  47. menu.SetActive(false);
  48. }
  49.  
  50. prevObj = obj;
  51. } else {
  52. obj.GetComponent<Renderer>().material.color = Color.blue;
  53. recupInfo();
  54.  
  55. prevObj = obj;
  56. }
  57. }
  58. }
  59.  
  60. void recupInfo() {
  61. //int nbSieges = GService.GetNombreSiege(obj.Name);
  62. menu.SetActive(true);
  63. string nomPays = obj.GetComponent<PaysView>().Nom;
  64. Debug.Log(nomPays);
  65. txt_nomPays = GetComponent<Text>();
  66. txt_nomPays.text = nomPays;
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement