mirror of
https://github.com/Leahnaya/TheKingsRace.git
synced 2026-08-28 05:14:04 -05:00
King Place updated
>the king can place things on the grid, and they snap to the grid >Hail and Slime are just placeholder objects at the moment >Grid snapping might need to be cleaned up
This commit is contained in:
@@ -2,13 +2,14 @@ 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);
|
||||
}
|
||||
|
||||
|
||||
//Is called when the King clicks on the Hail button
|
||||
public void OnHailClicked() {
|
||||
PlaceObject(1);
|
||||
@@ -31,26 +32,26 @@ public class KingPlace : MonoBehaviour {
|
||||
public GameObject Slime;
|
||||
public GameObject Grid;
|
||||
private GameObject Place;
|
||||
private GameObject PlaceTemp;
|
||||
private bool Placing = false;
|
||||
private bool HailPlacing = false;
|
||||
private bool SlimePlacing = false;
|
||||
|
||||
private void PlaceObject(int ID) {
|
||||
//Switch statement, ID-0 = Block,ID-1 = Hail,ID-2 = Slime
|
||||
switch (ID) {//Parses in the button clicked into the right object that the King is placing
|
||||
case 0:
|
||||
Debug.Log("B");
|
||||
Place = Block;
|
||||
break;
|
||||
case 1:
|
||||
Debug.Log("H");
|
||||
Place = Hail;
|
||||
break;
|
||||
case 2:
|
||||
Debug.Log("S");
|
||||
Place = Slime;
|
||||
break;
|
||||
}
|
||||
//Create the object that will follow the Mouse
|
||||
//Instantiate(Place);
|
||||
PlaceTemp = Instantiate(Place);
|
||||
//Layout the grid
|
||||
Grid.GetComponent<GridReveal>().GridSwitch(true);
|
||||
|
||||
@@ -61,24 +62,64 @@ public class KingPlace : MonoBehaviour {
|
||||
[SerializeField] private Camera KingCam;
|
||||
[SerializeField] private LayerMask LayerMask;
|
||||
|
||||
private void Update() {
|
||||
if(Placing == true) {
|
||||
Ray Ray = KingCam.ScreenPointToRay(Input.mousePosition);
|
||||
private void FixedUpdate() {
|
||||
if (Placing == true) {
|
||||
Ray Ray = KingCam.ScreenPointToRay(Input.mousePosition);//Raycast to find the point where the mouse cursor is
|
||||
if (Physics.Raycast(Ray, out RaycastHit RayCastHit, float.MaxValue, LayerMask)) {
|
||||
Place.transform.position = RayCastHit.point;
|
||||
PlaceTemp.transform.position = RayCastHit.point;
|
||||
}
|
||||
if (Input.GetMouseButtonUp(1)) {//Reads the player letting up the right mouse button
|
||||
//foreach (Transform child in Grid.gameObject.transform) { //Finds the correct Row the cursor is in (Commented out because it's scuffed AF)
|
||||
//if (child.transform.position.z >= Place.transform.position.x && child.transform.position.z - 20 <= Place.transform.position.x)
|
||||
//{
|
||||
// Debug.Log("Help" + child.transform.position.z);
|
||||
//Place the object (Snap it up and to Grid)
|
||||
Instantiate(Place);
|
||||
//break;
|
||||
//}
|
||||
if (Input.GetMouseButtonDown(0)) {//Reads the player clicking the left mouse button again
|
||||
FindGridBox();
|
||||
}
|
||||
}
|
||||
if (HailPlacing == true) {
|
||||
|
||||
}
|
||||
if (SlimePlacing == true) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private GameObject Row;
|
||||
private void FindGridBox() {
|
||||
int BoxSize = 20;
|
||||
float i = ((PlaceTemp.transform.position.x) - 101) / -BoxSize; //Finds the Row the cursor is in
|
||||
int RowNumb = (int)i; //Rounds it down
|
||||
float y = ((PlaceTemp.transform.position.z) - 626) / -BoxSize; //Finds the Box in the Row the cursor is in
|
||||
int Box = (int)y; //Rounds it down
|
||||
int x = (RowNumb * -BoxSize) + 101;//Sets it's X to the X of the Row
|
||||
int z = (Box * -BoxSize) + 626;//Sets its Z to the Z of the Box
|
||||
PlaceTemp.transform.position = new Vector3(x, PlaceTemp.transform.position.y, z);//fully snaps it to the grid
|
||||
GridCheck(RowNumb, Box);//Makes sure the Box is a valid position
|
||||
if (Place == Slime && SlimePlacing == false) {//If Object is Hail or Slime launch into other functions
|
||||
SlimePlc();
|
||||
}
|
||||
else if (Place == Hail && HailPlacing == false) {
|
||||
HailPlc();
|
||||
}
|
||||
}
|
||||
|
||||
private void GridCheck(int Row, int Box) {
|
||||
GameObject RowTrue;
|
||||
GameObject BoxTrue;
|
||||
RowTrue = Grid.transform.Find("Row" + Row).gameObject;
|
||||
if(RowTrue != null) {
|
||||
BoxTrue = RowTrue.transform.Find("GridChunk(0," + Box + ")").gameObject;
|
||||
if(BoxTrue != null) {
|
||||
Grid.GetComponent<GridReveal>().GridSwitch(false); //Switch off the grid
|
||||
Placing = false;//Stop placing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SlimePlc() {
|
||||
Grid.GetComponent<GridReveal>().GridSwitch(true);
|
||||
SlimePlacing = true;
|
||||
}
|
||||
|
||||
private void HailPlc() {
|
||||
Grid.GetComponent<GridReveal>().GridSwitch(true);
|
||||
SlimePlacing = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user