Advertisement
Guest User

Untitled

a guest
May 3rd, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.75 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4.  
  5. public class Licht : MonoBehaviour {
  6.     public int gk = 0;
  7.     public int Range = 0;
  8.     public Vector3[] hitted = new Vector3[360];
  9.     public PolygonCollider2D col;
  10.     void Start () {
  11.         print (col.points[1]);
  12.     }
  13.  
  14.     void Update () {
  15.         RaycastHit2D Test = Physics2D.CircleCast(transform.position,Range,transform.position);
  16.         if(Test.collider != null)
  17.         {
  18.             for(int i = 0;i<gk; i++)
  19.             {
  20.                 float x = Mathf.Cos(i/Mathf.Rad2Deg) * Range,y = Mathf.Sin(i/Mathf.Rad2Deg) * Range;
  21.                 RaycastHit2D hit = Physics2D.Raycast(transform.position,new Vector2(x,y),Range);
  22.                 if(hit.collider != null)
  23.                 {
  24.                     hitted[i] = hit.point;
  25.                     /*test[i] = hit.transform.position - (hit.collider.bounds.size / 2);
  26.                     test[i] = hit.transform.position + (hit.collider.bounds.size / 2);
  27.                     test[i] = hit.transform.position + (new Vector3(hit.collider.bounds.size.x/2,-hit.collider.bounds.size.y / 2,0));
  28.                     test[i] = hit.transform.position + (new Vector3(-hit.collider.bounds.size.x/2,hit.collider.bounds.size.y / 2,0));*/
  29.                 }
  30.                 else
  31.                 {
  32.                     hitted[i] = new Vector3(0,0,0);
  33.                 }
  34.  
  35.             }
  36.         }
  37.         else
  38.         {
  39.             for(int i = 0;i<gk;i++)
  40.             {
  41.                 hitted[i] = new Vector3(0,0,0);
  42.             }
  43.         }
  44.  
  45.     }
  46.  
  47.     void OnDrawGizmos()
  48.     {
  49.         for(int i = 0;i<gk;i++)
  50.         {
  51.  
  52.             float x = transform.position.x + Mathf.Cos(i/Mathf.Rad2Deg)* Range,y = transform.position.y + Mathf.Sin(i/Mathf.Rad2Deg) * Range;
  53.             if(hitted[i] != (new Vector3(0,0,0)))
  54.             {
  55.                 Gizmos.color = Color.white;
  56.                 Gizmos.DrawLine(transform.position,hitted[i]);
  57.                 Gizmos.color = Color.red;
  58.                 Gizmos.DrawSphere(hitted[i],0.05f);
  59.  
  60.             }
  61.             else
  62.             {
  63.                 Gizmos.color = Color.white;
  64.                 Gizmos.DrawLine(transform.position,new Vector2(x,y));
  65.             }
  66.         }
  67.        
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement