Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- using System.IO;
- public class GameManager : MonoBehaviour
- {
- [Tooltip("The color of the drawn lines")]
- public Color lineColor;
- public Material lineMaterial;
- public Transform Pencil;
- public Sprite SurpriseGlass;
- public Sprite HappyGlass;
- public Sprite SadGlass;
- public Slider PenCapacity;
- public Text PenPercent;
- [HideInInspector]
- public GameObject[] Hint;
- public Image Star1;
- public Image Star2;
- public Image Star3;
- public GameObject LevComp;
- private GameObject[] Obs;
- private List<GameObject> listLine = new List<GameObject>();
- public List<Vector2> listPoint = new List<Vector2>();
- private GameObject currentLine;
- public GameObject currentColliderObject;
- private GameObject hintTemp;
- private GameObject[] waterTap;
- private GameObject Glass;
- private Vector3 LastMosPos;
- private BoxCollider2D currentBoxCollider2D;
- private LineRenderer lines;
- private LineRenderer currentLineRenderer;
- private bool stopHolding;
- private bool allowDrawing = true;
- [HideInInspector]
- public bool completed;
- int clickCont;
- private List<Rigidbody2D> listObstacleNonKinematic = new List<Rigidbody2D>();
- private GameObject[] obstacles;
- float mosDis;
- bool canCreate;
- RaycastHit2D hit_1;
- RaycastHit2D hit_2;
- RaycastHit2D hit_3;
- GameObject TemLine;
- void Start()
- {
- Pencil.gameObject.SetActive(false);
- waterTap = GameObject.FindGameObjectsWithTag("Interactive");
- Glass = GameObject.FindGameObjectWithTag("GlassParent");
- Glass.GetComponent<Rigidbody2D>().bodyType = RigidbodyType2D.Static;
- Hint = GameObject.FindGameObjectsWithTag("Hint");
- for (int i = 0; i < Hint.Length; i++)
- {
- Hint[i].SetActive(false);
- }
- lineMaterial.SetColor("_Color", lineColor);
- Obs = GameObject.FindGameObjectsWithTag("Obstacle");
- for (int i = 0; i < Obs.Length; i++)
- {
- Obs[i].GetComponent<Rigidbody2D>().bodyType = RigidbodyType2D.Static;
- }
- }
- void Update()
- {
- if (PenCapacity.value <= 0.01f || !Input.GetMouseButton(0))
- {
- Pencil.gameObject.SetActive(false);
- }
- if (Input.GetMouseButtonDown(0))
- {
- GameObject thisButton = UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject; //Get the button on click
- if (thisButton != null) //Is click on button
- {
- allowDrawing = false;
- print("cant drwa");
- }
- else //Not click on button
- {
- allowDrawing = true;
- stopHolding = false;
- listPoint.Clear();
- CreateLine(Input.mousePosition);
- print("draw");
- }
- }
- else if (Input.GetMouseButton(0) && !stopHolding && allowDrawing && PenCapacity.value > 0)
- {
- RaycastHit2D rayHit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
- if (LastMosPos != Camera.main.ScreenToWorldPoint(Input.mousePosition))
- {
- if (rayHit.collider == null)
- {
- Pencil.gameObject.SetActive(true);
- Pencil.position = new Vector3(LastMosPos.x, LastMosPos.y, 0);
- if (canCreate == false)
- {
- float dist = Vector3.Distance(LastMosPos, Camera.main.ScreenToWorldPoint(Input.mousePosition));
- Pencil.GetComponent<TrignometricRotation>().enabled = true;
- PenCapacity.value = PenCapacity.value - dist / 25;
- PenPercent.text = Mathf.FloorToInt(PenCapacity.value * 100).ToString() + " %";
- if (Mathf.FloorToInt(PenCapacity.value * 100) < 75)
- {
- Star3.gameObject.SetActive(false);
- }
- if (Mathf.FloorToInt(PenCapacity.value * 100) < 50)
- {
- Star2.gameObject.SetActive(false);
- }
- if (Mathf.FloorToInt(PenCapacity.value * 100) < 25)
- {
- Star1.gameObject.SetActive(false);
- }
- }
- }
- }
- else
- {
- Pencil.GetComponent<TrignometricRotation>().enabled = false;
- }
- Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
- float ab = Vector2.Distance(LastMosPos, mousePos);
- mosDis = mosDis + ab;
- if (!listPoint.Contains(mousePos) && mosDis > .02f)
- {
- mosDis = 0;
- //Add mouse pos, set vertex and position for line renderer
- if (canCreate == false)
- {
- if (rayHit.collider == null)
- {
- listPoint.Add(mousePos);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement