1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- 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()
- {
- positionReset = transform.position;
- eulerAnglesReset = transform.eulerAngles;
- }
- // Update is called once per frame
- void Update()
- {
- if (Application.platform == RuntimePlatform.Android)
- {
- transform.Rotate(Vector3.up, Input.GetAxis("Mouse X") * speed * 2);
- transform.Rotate(Vector3.left, Input.GetAxis("Mouse Y") * speed * 2);
- transform.eulerAngles = new Vector3(transform.eulerAngles.x, transform.eulerAngles.y, 0);
- 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;
- }
- }
- }
- }
|