Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlaceTurret : MonoBehaviour
  6. {
  7.     private int tileLocationX;
  8.     private int tileLocationZ;
  9.  
  10.     [SerializeField] int minTileX;
  11.     [SerializeField] int maxTileX;
  12.     [SerializeField] int minTileY;
  13.     [SerializeField] int maxTileY;
  14.     // Start is called before the first frame update
  15.     void Start()
  16.     {
  17.         tileLocationX = Random.Range( minTileX, maxTileX );
  18.         tileLocationZ = Random.Range( minTileY, maxTileY );
  19.  
  20.  
  21.         //Debug.Log( "Trying to find floor: " + tileLocationX + ", " + tileLocationZ );
  22.         Vector3 newPos = new Vector3( tileLocationX, 30, tileLocationZ );
  23.         RaycastHit hit;
  24.         Debug.DrawRay( newPos, Vector3.down * 100, Color.white, 5 );
  25.         if( Physics.Raycast( newPos, Vector3.down, out hit, 100 ) )
  26.         {
  27.             //Debug.Log( "Hit ground" );
  28.             newPos.Set( newPos.x, hit.point.y, newPos.z );
  29.             //transform.Translate( 0, hit.point.y, 0 );
  30.         }
  31.         //Debug.Log( newPos );
  32.         transform.Translate( newPos,Space.World );
  33.  
  34.     }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement