Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.35 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine.SceneManagement;
  4. using UnityEngine.UI;
  5. using System.IO;
  6.  
  7.  
  8. public class GameManager : MonoBehaviour
  9. {
  10.  
  11. [Tooltip("The color of the drawn lines")]
  12. public Color lineColor;
  13. public Material lineMaterial;
  14. public Transform Pencil;
  15. public Sprite SurpriseGlass;
  16. public Sprite HappyGlass;
  17. public Sprite SadGlass;
  18. public Slider PenCapacity;
  19. public Text PenPercent;
  20. [HideInInspector]
  21. public GameObject[] Hint;
  22.  
  23. public Image Star1;
  24. public Image Star2;
  25. public Image Star3;
  26. public GameObject LevComp;
  27. private GameObject[] Obs;
  28. private List<GameObject> listLine = new List<GameObject>();
  29. public List<Vector2> listPoint = new List<Vector2>();
  30. private GameObject currentLine;
  31. public GameObject currentColliderObject;
  32. private GameObject hintTemp;
  33. private GameObject[] waterTap;
  34. private GameObject Glass;
  35. private Vector3 LastMosPos;
  36. private BoxCollider2D currentBoxCollider2D;
  37. private LineRenderer lines;
  38. private LineRenderer currentLineRenderer;
  39. private bool stopHolding;
  40. private bool allowDrawing = true;
  41. [HideInInspector]
  42. public bool completed;
  43. int clickCont;
  44. private List<Rigidbody2D> listObstacleNonKinematic = new List<Rigidbody2D>();
  45. private GameObject[] obstacles;
  46. float mosDis;
  47. bool canCreate;
  48. RaycastHit2D hit_1;
  49. RaycastHit2D hit_2;
  50. RaycastHit2D hit_3;
  51. GameObject TemLine;
  52. void Start()
  53. {
  54. Pencil.gameObject.SetActive(false);
  55. waterTap = GameObject.FindGameObjectsWithTag("Interactive");
  56. Glass = GameObject.FindGameObjectWithTag("GlassParent");
  57. Glass.GetComponent<Rigidbody2D>().bodyType = RigidbodyType2D.Static;
  58. Hint = GameObject.FindGameObjectsWithTag("Hint");
  59. for (int i = 0; i < Hint.Length; i++)
  60. {
  61. Hint[i].SetActive(false);
  62. }
  63. lineMaterial.SetColor("_Color", lineColor);
  64. Obs = GameObject.FindGameObjectsWithTag("Obstacle");
  65. for (int i = 0; i < Obs.Length; i++)
  66. {
  67. Obs[i].GetComponent<Rigidbody2D>().bodyType = RigidbodyType2D.Static;
  68. }
  69. }
  70.  
  71. void Update()
  72. {
  73. if (PenCapacity.value <= 0.01f || !Input.GetMouseButton(0))
  74. {
  75. Pencil.gameObject.SetActive(false);
  76. }
  77.  
  78. if (Input.GetMouseButtonDown(0))
  79. {
  80. GameObject thisButton = UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject; //Get the button on click
  81. if (thisButton != null) //Is click on button
  82. {
  83. allowDrawing = false;
  84. print("cant drwa");
  85. }
  86. else //Not click on button
  87. {
  88. allowDrawing = true;
  89. stopHolding = false;
  90. listPoint.Clear();
  91. CreateLine(Input.mousePosition);
  92. print("draw");
  93. }
  94. }
  95. else if (Input.GetMouseButton(0) && !stopHolding && allowDrawing && PenCapacity.value > 0)
  96. {
  97. RaycastHit2D rayHit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
  98. if (LastMosPos != Camera.main.ScreenToWorldPoint(Input.mousePosition))
  99. {
  100. if (rayHit.collider == null)
  101. {
  102.  
  103. Pencil.gameObject.SetActive(true);
  104. Pencil.position = new Vector3(LastMosPos.x, LastMosPos.y, 0);
  105. if (canCreate == false)
  106. {
  107. float dist = Vector3.Distance(LastMosPos, Camera.main.ScreenToWorldPoint(Input.mousePosition));
  108. Pencil.GetComponent<TrignometricRotation>().enabled = true;
  109. PenCapacity.value = PenCapacity.value - dist / 25;
  110. PenPercent.text = Mathf.FloorToInt(PenCapacity.value * 100).ToString() + " %";
  111. if (Mathf.FloorToInt(PenCapacity.value * 100) < 75)
  112. {
  113. Star3.gameObject.SetActive(false);
  114. }
  115. if (Mathf.FloorToInt(PenCapacity.value * 100) < 50)
  116. {
  117. Star2.gameObject.SetActive(false);
  118. }
  119. if (Mathf.FloorToInt(PenCapacity.value * 100) < 25)
  120. {
  121. Star1.gameObject.SetActive(false);
  122. }
  123. }
  124. }
  125. }
  126. else
  127. {
  128. Pencil.GetComponent<TrignometricRotation>().enabled = false;
  129. }
  130.  
  131. Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
  132. float ab = Vector2.Distance(LastMosPos, mousePos);
  133. mosDis = mosDis + ab;
  134.  
  135. if (!listPoint.Contains(mousePos) && mosDis > .02f)
  136. {
  137. mosDis = 0;
  138. //Add mouse pos, set vertex and position for line renderer
  139. if (canCreate == false)
  140. {
  141. if (rayHit.collider == null)
  142. {
  143. listPoint.Add(mousePos);
  144.  
  145.  
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement