Advertisement
Guest User

Untitled

a guest
Nov 13th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.10 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class LineManager : MonoBehaviour
  6. {
  7.     public GameObject pos1;
  8.     public GameObject pos2;
  9.  
  10.     [Header("Line Gameobject")]
  11.     public GameObject lineGameobject;
  12.     public Vector3 linePosition;
  13.  
  14.     [Header("Position Manager")]
  15.     public Vector3 firstPoint;
  16.     public Vector3 secondPoint;
  17.     [Space]
  18.     public float distanceBetweenPoints;
  19.  
  20.     [Header("Time Manager")]
  21.     public int lineCooldown;
  22.     [Space]
  23.     public float timeForFirstPoint;
  24.     public float timeForSecondPoint;
  25.  
  26.     [Header("Bools")]
  27.     public bool canSetFirstPoint;
  28.     public bool canSetSecondPoint;
  29.  
  30.     void Start()
  31.     {
  32.         canSetFirstPoint = true;
  33.         canSetSecondPoint = true;
  34.     }
  35.  
  36.     void Update()
  37.     {
  38.         pos1.transform.position = firstPoint;
  39.         pos2.transform.position = secondPoint;
  40.  
  41.  
  42.  
  43.         Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
  44.         mousePos.z = 0;
  45.  
  46.         linePosition = new Vector3(lineGameobject.transform.position.x, lineGameobject.transform.position.y, 0);
  47.  
  48.         distanceBetweenPoints = Vector3.Distance(firstPoint, secondPoint);
  49.         lineGameobject.transform.position = new Vector3(secondPoint.x+firstPoint.x/2,secondPoint.y+firstPoint.y/2,0);
  50.  
  51.         if (timeForFirstPoint <= lineCooldown)
  52.         {
  53.             timeForFirstPoint += Time.deltaTime;
  54.         } else
  55.         {
  56.             canSetFirstPoint = true;
  57.         }
  58.  
  59.         if (timeForSecondPoint <= lineCooldown)
  60.         {
  61.             timeForSecondPoint += Time.deltaTime;
  62.         }
  63.         else
  64.         {
  65.             canSetSecondPoint = true;
  66.         }
  67.  
  68.         if (Input.GetKeyDown(KeyCode.Mouse0) && canSetFirstPoint)
  69.         {
  70.             timeForFirstPoint = 0;
  71.             canSetFirstPoint = false;
  72.             firstPoint = mousePos;
  73.         }
  74.         if (Input.GetKeyDown(KeyCode.Mouse1) && canSetSecondPoint)
  75.         {
  76.             timeForSecondPoint = 0;
  77.             canSetSecondPoint = false;
  78.             secondPoint = mousePos;
  79.         }
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement