123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- 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<CharacterController>();
- 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;
- }
- //***********************************场景切换******************************//
- /// <summary>
- /// 大门
- /// </summary>
- 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);
- }
- /// <summary>
- /// 进线区
- /// </summary>
- 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);
- }
- /// <summary>
- /// 主变区
- /// </summary>
- 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);
- }
- /// <summary>
- /// 馈线区
- /// </summary>
- 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);
- }
- /// <summary>
- /// 控制室
- /// </summary>
- 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);
- }
- /// <summary>
- /// 电容室
- /// </summary>
- 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);
- }
- /// <summary>
- /// 大楼屋顶
- /// </summary>
- 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);
- }
- /// <summary>
- /// 10kv高压室
- /// </summary>
- 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);
- }
- /// <summary>
- /// 27.5kv高压室
- /// </summary>
- 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);
- }
- }
|