Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class Crosshair : MonoBehaviour {
- public float largura = 0.5f;
- public float altura = 0.5f;
- public float distancia;
- public Image[] crosshairX;
- public Image[] crosshairY;
- public Color cor;
- WeaponBase arma;
- public GameObject armas;
- float dist2;
- float larg;
- float alt;
- float dist;
- Color c;
- void Start()
- {
- ChangeCrosshair();
- dist2 = distancia;
- }
- void Update()
- {
- arma = armas.GetComponentInChildren<WeaponBase>();
- distancia = (arma.precisao*3)+dist2;
- if(larg != largura || alt!=altura || dist!=dist2 || c != cor)
- {
- ChangeCrosshair();
- }
- larg = largura;
- alt = altura;
- dist = distancia;
- c = cor;
- }
- private void ChangeCrosshair()
- {
- RectTransform rtx1 = crosshairX[0].GetComponent<RectTransform>();
- RectTransform rtx2 = crosshairX[1].GetComponent<RectTransform>();
- RectTransform rty1 = crosshairY[0].GetComponent<RectTransform>();
- RectTransform rty2 = crosshairY[1].GetComponent<RectTransform>();
- Vector2 patternSizeX = new Vector2(altura, largura);
- Vector2 patternSizeY = new Vector2(largura, altura);
- Vector2 patternPosX1 = new Vector2((Screen.width/2) + (distancia), (Screen.height/2));
- Vector2 patternPosX2 = new Vector2((Screen.width/2) - (distancia), (Screen.height/2));
- Vector2 patternPosY1 = new Vector2((Screen.width/2), (Screen.height/2) + (distancia));
- Vector2 patternPosY2 = new Vector2((Screen.width/2), (Screen.height/2) - (distancia));
- for (int x = 0; x <= 1; x++)
- {
- crosshairX[x].GetComponent<RectTransform>().localScale = patternSizeX;
- crosshairY[x].GetComponent<RectTransform>().localScale = patternSizeY;
- crosshairX[x].color = cor;
- crosshairY[x].color = cor;
- }
- crosshairX[0].GetComponent<RectTransform>().position = patternPosX1;
- crosshairX[1].GetComponent<RectTransform>().position = patternPosX2;
- crosshairY[0].GetComponent<RectTransform>().position = patternPosY1;
- crosshairY[1].GetComponent<RectTransform>().position = patternPosY2;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement