mirror of
https://github.com/Leahnaya/TheKingsRace.git
synced 2026-08-28 13:24:07 -05:00
King Zoom Functionality
>The King can now zoom >UI follows them in >Then can rotate their Veiw up and down
This commit is contained in:
@@ -43,7 +43,7 @@ public class KingPlace : NetworkBehaviour
|
||||
private KingAbility KABump = new KingAbility(6, 10);
|
||||
|
||||
|
||||
private float[] MountPlats = { 303.41f, 315.5f, 330.5f, 345.5f, 360.5f, 400.5f, 415.5f, 430.5f, 470.5f, 485.5f, 500.5f };
|
||||
private float[] MountPlats = { 302f, 314f, 329f, 344f, 359f, 399f, 414f, 429f, 469f, 484f, 499f, 514f};
|
||||
private float[] MountxOffsets = { -50f, -73.4f, -100f, -127f, -134.7f, -130f, -34f, 14.5f, 91.2f, 129f, 129.5f };
|
||||
private float[] MountzOffsets = { 130f, 120f, 97f, 56.6f, 32f, -50f, -135.5f, -138.5f, -105f, -52.5f, 50f };
|
||||
|
||||
@@ -186,8 +186,8 @@ public class KingPlace : NetworkBehaviour
|
||||
if (PlaceTemp.transform.position.x < MontStr.x) {//King is trying to place on the mountain
|
||||
Platform = null;
|
||||
bool found = false;
|
||||
for(int i = 0; i < MountPlats.Length; i++) {
|
||||
if (MountPlats[i] == PlaceTemp.transform.position.y) {//Finds the platform by comparing y values
|
||||
for(int i = 0; i < MountPlats.Length-1; i++) {
|
||||
if (MountPlats[i] <= PlaceTemp.transform.position.y && MountPlats[i+1] >= PlaceTemp.transform.position.y) {//Finds the platform by comparing y values
|
||||
Platform = MountGrid.transform.Find("Platform" + i).gameObject;//Sets the platform and offsets for that platform
|
||||
MountxOffset = MountxOffsets[i];
|
||||
MountzOffset = MountzOffsets[i];
|
||||
@@ -299,9 +299,8 @@ public class KingPlace : NetworkBehaviour
|
||||
{//King is trying to place on the mountain
|
||||
Platform = null;
|
||||
bool found = false;
|
||||
for (int i = 0; i < MountPlats.Length; i++)
|
||||
{
|
||||
if (MountPlats[i] == PlaceTemp.transform.position.y)
|
||||
for (int i = 0; i < MountPlats.Length-1; i++) {
|
||||
if (MountPlats[i] <= PlaceTemp.transform.position.y && MountPlats[i + 1] >= PlaceTemp.transform.position.y)
|
||||
{//Finds the platform by comparing y values
|
||||
Platform = MountGrid.transform.Find("Platform" + i).gameObject;//Sets the platform and offsets for that platform
|
||||
MountxOffset = MountxOffsets[i];
|
||||
@@ -397,7 +396,7 @@ public class KingPlace : NetworkBehaviour
|
||||
|
||||
Arrow.SetActive(true);
|
||||
SlimeBody.transform.LookAt(Arrow.transform);
|
||||
SlimeBody.transform.Rotate(0, -90, 0);
|
||||
SlimeBody.transform.Rotate(0, -90, -5);
|
||||
return DirNumber;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,15 +4,64 @@ using UnityEngine;
|
||||
|
||||
public class KingZoom : MonoBehaviour
|
||||
{
|
||||
|
||||
Camera cam;
|
||||
Quaternion BaseRot;
|
||||
|
||||
public GameObject Panel;
|
||||
public GameObject Text;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
cam = gameObject.GetComponent<Camera>();//Gets the camera and its rotation
|
||||
BaseRot = transform.rotation;
|
||||
}
|
||||
|
||||
bool Zoomed = false;
|
||||
float RotSpeed = .5f;
|
||||
float minXAngle = 40f;
|
||||
float maxXAngle = 70f;
|
||||
float minYAngle = -45f;
|
||||
float maxYAngle = 45f;
|
||||
|
||||
float XAng, YAng;
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
if (Input.GetKeyUp(KeyCode.W))//Switches in and out of zoom
|
||||
{
|
||||
if (Zoomed == false)
|
||||
{
|
||||
cam.fieldOfView = 15;//Zooms in
|
||||
Panel.transform.localPosition = new Vector3(Panel.transform.localPosition.x, Panel.transform.localPosition.y, 4150f);//Moves the UI Text in with the zoom
|
||||
Text.transform.localPosition = new Vector3(Text.transform.localPosition.x, Text.transform.localPosition.y, 4150f);
|
||||
Zoomed = true;
|
||||
}
|
||||
else if (Zoomed == true)
|
||||
{
|
||||
cam.fieldOfView = 40;//Zooms out
|
||||
Panel.transform.localPosition = new Vector3(Panel.transform.localPosition.x, Panel.transform.localPosition.y, 1510f);//Moves the UI Text out with the zoom
|
||||
Text.transform.localPosition = new Vector3(Text.transform.localPosition.x, Text.transform.localPosition.y, 1510f);
|
||||
transform.rotation = BaseRot;
|
||||
Zoomed = false;
|
||||
}
|
||||
}
|
||||
if(Zoomed == true)//If Zoomed in allows the King to rotate their veiw up and down
|
||||
{
|
||||
Vector3 MosPos = Input.mousePosition;
|
||||
if (MosPos.y < 100)//Looks down
|
||||
{
|
||||
transform.Rotate(RotSpeed, 0, 0);
|
||||
XAng = Mathf.Clamp(cam.transform.localEulerAngles.x, minXAngle, maxXAngle);
|
||||
cam.transform.localEulerAngles = new Vector3(XAng, cam.transform.localEulerAngles.y, cam.transform.localEulerAngles.z);
|
||||
}
|
||||
if (MosPos.y > 1000)//Looks up
|
||||
{
|
||||
transform.Rotate(-RotSpeed, 0, 0);
|
||||
XAng = Mathf.Clamp(cam.transform.localEulerAngles.x, minXAngle, maxXAngle);
|
||||
cam.transform.localEulerAngles = new Vector3(XAng, cam.transform.localEulerAngles.y, cam.transform.localEulerAngles.z);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user