123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace SC.XR.Unity
- {
- public class ControlTransform : MonoBehaviour
- {
- [Range(0.1f, 10f)]
- public float speed = 0.4f;
- Vector3 positionReset, eulerAnglesReset;
- void Awake()
- {
- this.gameObject.AddComponent<AllMoveEvent>();
- positionReset = transform.position;
- eulerAnglesReset = transform.eulerAngles;
- }
- // Update is called once per frame
- void Update()
- {
- #if UNITY_EDITOR
- if (Application.platform == RuntimePlatform.Android|| Application.platform == RuntimePlatform.IPhonePlayer)
- return;
- if (Input.GetKey(KeyCode.W))
- {
- transform.Translate(Vector3.forward * Time.deltaTime * speed);
- }
- else if (Input.GetKey(KeyCode.S))
- {
- transform.Translate(Vector3.back * Time.deltaTime * speed);
- }
- if (Input.GetKey(KeyCode.A))
- {
- transform.Translate(Vector3.left * Time.deltaTime * speed);
- }
- else if (Input.GetKey(KeyCode.D))
- {
- transform.Translate(Vector3.right * Time.deltaTime * speed);
- }
- if (Input.GetMouseButton(0) || Input.GetMouseButton(1))
- {
- transform.Rotate(Vector3.up, Input.GetAxis("Mouse X") * speed * 10);
- transform.Rotate(Vector3.left, Input.GetAxis("Mouse Y") * speed * 10);
- transform.eulerAngles = new Vector3(transform.eulerAngles.x, transform.eulerAngles.y, 0);
- }
- if (Input.GetKey(KeyCode.Escape))
- {
- transform.position = positionReset;
- transform.eulerAngles = eulerAnglesReset;
- }
- #endif
- }
- }
- }
|