Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class LineManager : MonoBehaviour
- {
- public GameObject pos1;
- public GameObject pos2;
- [Header("Line Gameobject")]
- public GameObject lineGameobject;
- public Vector3 linePosition;
- [Header("Position Manager")]
- public Vector3 firstPoint;
- public Vector3 secondPoint;
- [Space]
- public float distanceBetweenPoints;
- [Header("Time Manager")]
- public int lineCooldown;
- [Space]
- public float timeForFirstPoint;
- public float timeForSecondPoint;
- [Header("Bools")]
- public bool canSetFirstPoint;
- public bool canSetSecondPoint;
- void Start()
- {
- canSetFirstPoint = true;
- canSetSecondPoint = true;
- }
- void Update()
- {
- pos1.transform.position = firstPoint;
- pos2.transform.position = secondPoint;
- Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
- mousePos.z = 0;
- linePosition = new Vector3(lineGameobject.transform.position.x, lineGameobject.transform.position.y, 0);
- distanceBetweenPoints = Vector3.Distance(firstPoint, secondPoint);
- lineGameobject.transform.position = new Vector3(secondPoint.x+firstPoint.x/2,secondPoint.y+firstPoint.y/2,0);
- if (timeForFirstPoint <= lineCooldown)
- {
- timeForFirstPoint += Time.deltaTime;
- } else
- {
- canSetFirstPoint = true;
- }
- if (timeForSecondPoint <= lineCooldown)
- {
- timeForSecondPoint += Time.deltaTime;
- }
- else
- {
- canSetSecondPoint = true;
- }
- if (Input.GetKeyDown(KeyCode.Mouse0) && canSetFirstPoint)
- {
- timeForFirstPoint = 0;
- canSetFirstPoint = false;
- firstPoint = mousePos;
- }
- if (Input.GetKeyDown(KeyCode.Mouse1) && canSetSecondPoint)
- {
- timeForSecondPoint = 0;
- canSetSecondPoint = false;
- secondPoint = mousePos;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement