Advertisement
gaidzinski07

Crosshair.cs

Aug 20th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.34 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class Crosshair : MonoBehaviour {
  6.  
  7.     public float largura = 0.5f;
  8.     public float altura = 0.5f;
  9.     public float distancia;
  10.     public Image[] crosshairX;
  11.     public Image[] crosshairY;
  12.     public Color cor;
  13.     WeaponBase arma;
  14.     public GameObject armas;
  15.     float dist2;
  16.     float larg;
  17.     float alt;
  18.     float dist;
  19.     Color c;
  20.  
  21.     void Start()
  22.     {
  23.         ChangeCrosshair();
  24.         dist2 = distancia;
  25.     }
  26.     void Update()
  27.     {
  28.         arma = armas.GetComponentInChildren<WeaponBase>();
  29.         distancia = (arma.precisao*3)+dist2;
  30.         if(larg != largura || alt!=altura || dist!=dist2 || c != cor)
  31.         {
  32.             ChangeCrosshair();
  33.         }
  34.         larg = largura;
  35.         alt = altura;
  36.         dist = distancia;
  37.         c = cor;
  38.     }
  39.     private void ChangeCrosshair()
  40.     {
  41.         RectTransform rtx1 = crosshairX[0].GetComponent<RectTransform>();
  42.         RectTransform rtx2 = crosshairX[1].GetComponent<RectTransform>();
  43.         RectTransform rty1 = crosshairY[0].GetComponent<RectTransform>();
  44.         RectTransform rty2 = crosshairY[1].GetComponent<RectTransform>();
  45.  
  46.         Vector2 patternSizeX = new Vector2(altura, largura);
  47.         Vector2 patternSizeY = new Vector2(largura, altura);
  48.  
  49.         Vector2 patternPosX1 = new Vector2((Screen.width/2) + (distancia), (Screen.height/2));
  50.         Vector2 patternPosX2 = new Vector2((Screen.width/2) - (distancia), (Screen.height/2));
  51.  
  52.         Vector2 patternPosY1 = new Vector2((Screen.width/2), (Screen.height/2) + (distancia));
  53.         Vector2 patternPosY2 = new Vector2((Screen.width/2), (Screen.height/2) - (distancia));
  54.  
  55.         for (int x = 0; x <= 1; x++)
  56.         {
  57.             crosshairX[x].GetComponent<RectTransform>().localScale = patternSizeX;
  58.             crosshairY[x].GetComponent<RectTransform>().localScale = patternSizeY;
  59.             crosshairX[x].color = cor;
  60.             crosshairY[x].color = cor;
  61.         }
  62.         crosshairX[0].GetComponent<RectTransform>().position = patternPosX1;
  63.         crosshairX[1].GetComponent<RectTransform>().position = patternPosX2;
  64.         crosshairY[0].GetComponent<RectTransform>().position = patternPosY1;
  65.         crosshairY[1].GetComponent<RectTransform>().position = patternPosY2;
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement