Advertisement
Guest User

DungeonRaycast

a guest
Apr 8th, 2020
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.87 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.     bool DirectionChecked = false;
  15.  
  16.     public Dungeon dSpawn;
  17.  
  18.     void Start()
  19.     {
  20.        
  21.     }
  22.  
  23.     // Update is called once per frame
  24.     void Update()
  25.     {
  26.        
  27.     }
  28.  
  29.     public void RaycastCheck()
  30.     {
  31.         if (DirectionChecked == false)
  32.         {
  33.             ///Direction = Random.Range(0, 4);
  34.  
  35.             if (Direction == 0 && Up == true)
  36.             {
  37.                 RaycastHit2D hit = Physics2D.Raycast(Up.transform.position, Up.transform.TransformDirection(Vector2.up), 1f);
  38.                 Debug.DrawRay(Up.transform.position, hit.point, Color.green);
  39.                 if (hit != true)
  40.                 {
  41.                     print("didnt hit anything up");
  42.                     dSpawn.dungeonUp();
  43.                     DirectionChecked = true;
  44.                 }
  45.                 else { print("HitCube up"); }
  46.                 RaycastCheck();
  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.                     DirectionChecked = true;
  57.                 }
  58.                 else { print("HitCube  down"); }
  59.                 RaycastCheck();
  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.                     DirectionChecked = true;
  70.  
  71.                 }
  72.                 else { print("HitCube left"); }
  73.                 RaycastCheck();
  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.                     DirectionChecked = true;
  84.                 }
  85.                 else { print("HitCube right"); }
  86.                 RaycastCheck();
  87.             }
  88.         }
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement