Grid Dynamic Reveal/Raycasting

>Grid Dynamic Reveal works in the actual scene
>Created duplicate scene to practice impliment the King
>Layed out the full Grid on the terrain
>Used Raycasting to find the position of the cursor in 3D world space
>Have the object that is going to be placed follow the King's Cursor
This commit is contained in:
Katherine
2021-12-10 20:31:00 -06:00
parent 8c6de35fd7
commit 98d69fdfea
6 changed files with 964991 additions and 48 deletions

View File

@@ -2,8 +2,8 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class KingPlace : MonoBehaviour
{
public class KingPlace : MonoBehaviour {
//Is called when the King clicks on the Block button
public void OnBlockClicked() {
PlaceObject(0);
@@ -30,10 +30,11 @@ public class KingPlace : MonoBehaviour
public GameObject Hail;
public GameObject Slime;
public GameObject Grid;
private GameObject Place;
private bool Placing = false;
private void PlaceObject(int ID) {
Grid.GetComponent<GridReveal>().GridSwitch(true);
//Switch statement, ID-0 = Block,ID-1 = Hail,ID-2 = Slime
GameObject Place;
switch (ID) {//Parses in the button clicked into the right object that the King is placing
case 0:
Debug.Log("B");
@@ -49,17 +50,27 @@ public class KingPlace : MonoBehaviour
break;
}
//Layout the grid
/* Have grid always existing? and Enable it for the King to see?
* Draw the grid dynamically based on the King's Camera?
* Draw it/Have it show up around the mouse cursor?
*/
Grid.GetComponent<GridReveal>().GridSwitch(true);
//The player selects where on the grid they want to place the object
/* Center anchored
* Should be "simple" to snap the cursor poistion onto the grid.
*/
Placing = true;
/* Center anchored
* Should be "simple" to snap the cursor poistion onto the grid.
*/
//The object is placed there
//Energy is spent
}
[SerializeField] private Camera KingCam;
[SerializeField] private LayerMask LayerMask;
private void Update() {
if(Placing == true) {
Ray Ray = KingCam.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(Ray, out RaycastHit RayCastHit, float.MaxValue, LayerMask)) {
Place.transform.position = RayCastHit.point;
}
}
}
}