Advertisement
Guest User

DungeonRaycast

a guest
Apr 9th, 2020
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.83 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class DungeonRaycastCheck : MonoBehaviour
  6. {
  7.     // Start is called before the first frame update
  8.  
  9.     public GameObject left;
  10.     public GameObject Right;
  11.     public GameObject Up;
  12.     public GameObject Down;
  13.     int Direction = 0;
  14.  
  15.     public static DungeonRaycastCheck instance;
  16.  
  17.     void Start()
  18.     {
  19.         instance = this;
  20.     }
  21.  
  22.     // Update is called once per frame
  23.     void Update()
  24.     {
  25.        
  26.     }
  27.  
  28.     public void RaycastCheck()
  29.     {
  30.         for (; Direction < 4;)
  31.         {
  32.             ///Direction = Random.Range(0, 4);
  33.  
  34.             if (Direction == 0 && Up == true)
  35.             {
  36.                 RaycastHit2D hit = Physics2D.Raycast(Up.transform.position, Up.transform.TransformDirection(Vector2.up), 1f);
  37.                 Debug.DrawRay(Up.transform.position, hit.point, Color.green);
  38.                 if (hit != true)
  39.                 {
  40.                     print("didnt hit anything up");
  41.                    
  42.                     Direction = 1;
  43.                    
  44.                 }
  45.                 else { print("HitCube up"); }
  46.                 Direction = 1;
  47.  
  48.             }
  49.             else if (Direction == 1 && Down == true)
  50.             {
  51.                 RaycastHit2D hit = Physics2D.Raycast(Down.transform.position, Down.transform.TransformDirection(Vector2.down), 1f);
  52.                 Debug.DrawRay(Down.transform.position, hit.point, Color.green);
  53.                 if (hit != true)
  54.                 {
  55.                     print("didnt hit anything down");
  56.                     Direction = 2;
  57.                 }
  58.                 else { print("HitCube  down"); }
  59.                 Direction = 2;
  60.             }
  61.  
  62.             else if (Direction == 2 && left == true)
  63.             {
  64.                 RaycastHit2D hit = Physics2D.Raycast(Right.transform.position, Right.transform.TransformDirection(-Vector2.right), 1f);
  65.                 Debug.DrawRay(left.transform.position, hit.point, Color.green);
  66.                 if (hit != true)
  67.                 {
  68.                     print("didnt hit anything left");
  69.                     Direction = 3;
  70.  
  71.                 }
  72.                 else { print("HitCube left"); }
  73.                 Direction = 3;
  74.             }
  75.  
  76.             else if (Direction == 3 && Right == true)
  77.             {
  78.                 RaycastHit2D hit = Physics2D.Raycast(left.transform.position, left.transform.TransformDirection(Vector2.left), 1f);
  79.                 Debug.DrawRay(Right.transform.position, hit.point, Color.green);
  80.                 if (hit != true)
  81.                 {
  82.                     print("didnt hit anything right");
  83.                     Direction = 4;
  84.                 }
  85.                 else { print("HitCube right"); }
  86.                 Direction = 4;
  87.             }
  88.         }
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement