Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class Distance: MonoBehaviour {
- Texture2D textureDr;
- Texture2D textureAbravanel;
- void Start() {
- int sizeX = 201;
- int sizeY = 201;
- textureDr = new Texture2D(sizeX, sizeY);
- textureAbravanel = new Texture2D(sizeX, sizeY);
- Vector2 point = new Vector2(100, 100);
- for(int x = 0; x < sizeX; x++) {
- for(int y = 0; y < sizeY; y++) {
- if(IsPointInRangeOfPoint2D(new Vector2(x, y), point, 10F))
- textureDr.SetPixel(x, y, Color.green);
- else
- textureDr.SetPixel(x, y, Color.red);
- if(IsPlayerInRangeOfXY(new Vector2(x, y), 10F, point.x, point.y))
- textureAbravanel.SetPixel(x, y, Color.green);
- else
- textureAbravanel.SetPixel(x, y, Color.red);
- }
- }
- textureDr.Apply();
- textureAbravanel.Apply();
- }
- bool IsPointInRangeOfPoint2D(Vector2 point1, Vector2 point2, float range) {
- Vector2 newPoint = new Vector2(point1.x - point2.x, point1.y - point2.y);
- float distance = Mathf.Abs(Mathf.Sqrt((newPoint.x * newPoint.x) + (newPoint.y * newPoint.y)));
- if(distance <= range)
- return true;
- return false;
- }
- bool IsPlayerInRangeOfXY(Vector2 point, float radius, float x, float y) {
- float[] velha = new float[2] { point.x, point.y };
- float[] nova = new float[2] {
- (velha[0] - x),
- (velha[1] - y)
- };
- if(((nova[0] < radius) && (nova[1] > -radius)))
- return true;
- return false;
- }
- void OnGUI() {
- GUI.DrawTexture(new Rect(Screen.width * 0.5F - 250, Screen.height * 0.5F - 100, 201, 201), textureDr);
- GUI.DrawTexture(new Rect(Screen.width * 0.5F + 50, Screen.height * 0.5F - 100, 201, 201), textureAbravanel);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement