using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class PlayerController : MonoBehaviour { public Transform camera; public Vector3 position; public Vector3 currentposition; public Quaternion rotation; public static CharacterController character; public Transform mapIcon; public float moveSpeed; public float jumpSpeed; private float horizontalMove, verticalMove; public Vector3 dir; public static float gravity; public float g; private Vector3 velocity; public Button walk_or_fly; public Transform groundCheck; public float checkRadius; public LayerMask groundLayer; public bool isGround; // Start is called before the first frame update //public bool isWalk = true; public float chight; public float phight; void Start() { character = GetComponent(); position = character.transform.position; rotation = character.transform.rotation; chight = camera.transform.position.y; phight = character.transform.position.y; } // Update is called once per frame void Update() { if (ButtonsController.isWalk) { isGround = Physics.CheckSphere(groundCheck.position, checkRadius, groundLayer); if (isGround && velocity.y < 0) { velocity = new Vector3(0, 0, 0); } else { if (gravity == 0) { velocity = new Vector3(0, 0, 0); } } horizontalMove = Input.GetAxis("Horizontal") * moveSpeed; verticalMove = Input.GetAxis("Vertical") * moveSpeed; dir = transform.forward * verticalMove + transform.right * horizontalMove; if (Input.GetKey(KeyCode.LeftShift)) { dir *= 3f; } character.Move(dir * Time.deltaTime); if (Input.GetButtonDown("Jump") && isGround) { velocity.y = jumpSpeed; } if (Input.GetKeyDown(KeyCode.R)) { Physics.autoSyncTransforms = true; character.transform.position = position; character.transform.rotation = rotation; } velocity.y -= gravity * Time.deltaTime; character.Move(velocity * Time.deltaTime); currentposition = character.transform.position; } else { Physics.autoSyncTransforms = true; character.transform.position = camera.position; character.transform.rotation = new Quaternion(0, camera.rotation.y, 0, camera.rotation.w);//*/camera.rotation; } g = gravity; } //***********************************场景切换******************************// /// /// 大门 /// public void OnClickBtnGate() { ButtonsController.isWalk = true; Physics.autoSyncTransforms = true; character.transform.position = new Vector3(10.0f,2.00f,30.0f); character.transform.localEulerAngles = new Vector3(0, -180.0f, 0); camera.localRotation = Quaternion.Euler(340, 0, 0); } /// /// 进线区 /// public void OnClickBtnIncoming() { ButtonsController.isWalk = true; Physics.autoSyncTransforms = true; character.transform.position = new Vector3(32.0f, 2.0f, 2.0f); character.transform.localEulerAngles = new Vector3(1.0f, -153.0f, 0); camera.localRotation = Quaternion.Euler(330, 360, 0); } /// /// 主变区 /// public void OnClickBtnMaintransformer() { ButtonsController.isWalk = true; Physics.autoSyncTransforms = true; character.transform.position = new Vector3(8.0f, 2.0f, -10.0f); character.transform.localEulerAngles = new Vector3(0, -30.0f, 0); camera.localRotation = Quaternion.Euler(345, 360, 0); } /// /// 馈线区 /// public void OnClickBtnFeeder() { ButtonsController.isWalk = true; Physics.autoSyncTransforms = true; character.transform.position = new Vector3(-27.0f, 2.0f, 20.0f); character.transform.localEulerAngles = new Vector3(0, -200, 0); camera.localRotation = Quaternion.Euler(0, 360, 0); } /// /// 控制室 /// public void OnClickBtnControl() { ButtonsController.isWalk = true; Physics.autoSyncTransforms = true; character.transform.position = new Vector3(-14.95235f, 9.0f, -20.0f); character.transform.localEulerAngles = new Vector3(0, -360, 0); camera.localRotation = Quaternion.Euler(350, 0, 0); } /// /// 电容室 /// public void OnClickBtnCapacitance() { ButtonsController.isWalk = true; Physics.autoSyncTransforms = true; character.transform.position = new Vector3(-14.7f, 9.0f, 1.0f); character.transform.localEulerAngles = new Vector3(0, -360, 0); camera.localRotation = Quaternion.Euler(350, 0, 0); } /// /// 大楼屋顶 /// public void OnClickBtnRoof() { ButtonsController.isWalk = true; Physics.autoSyncTransforms = true; character.transform.position = new Vector3(-12.0f, 16.0f, -20.0f); character.transform.localEulerAngles = new Vector3(0, -350.0f, 0); camera.localRotation = Quaternion.Euler(360, 0, 0); } /// /// 10kv高压室 /// public void OnClickBtn10kv() { ButtonsController.isWalk = true; Physics.autoSyncTransforms = true; character.transform.position = new Vector3(12.0f, 2.0f, -24.0f); character.transform.localEulerAngles = new Vector3(0, -270, 0); camera.localRotation = Quaternion.Euler(350, 0, 0); } /// /// 27.5kv高压室 /// public void OnClickBtn275kv() { ButtonsController.isWalk = true; Physics.autoSyncTransforms = true; character.transform.position = new Vector3(-15.0f,2.0f, -5.0f); character.transform.localEulerAngles = new Vector3(0, -360.0f, 0); camera.localRotation = Quaternion.Euler(360, 0, 0); } public void setFly() { gravity = 0; camera.localPosition = new Vector3(0, 0, 0); } public void setWalk() { gravity = 9.81f; camera.localPosition = new Vector3(0, 0, 0); } }