Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class UseScript : MonoBehaviour {
- public GameObject pivotPoint;
- bool moveDirection = false; // false - close to open, true - open to close
- bool doMove = false;
- GameObject door = null;
- // Use this for initialization
- void Start () {
- Cursor.visible = false;
- door = this.gameObject;
- }
- // Update is called once per frame
- void Update () {
- Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
- RaycastHit hit;
- GameObject objectHit = null;
- if (Physics.Raycast(ray, out hit, 100.0f)) {
- // Debug.DrawLine (ray.origin, hit.point);
- objectHit = hit.collider.gameObject;
- }
- GameObject player = GameObject.Find("RigidBodyFPSController");
- if (Input.GetKeyDown(KeyCode.E) && (objectHit != null))
- {
- float distance = Vector3.Distance(objectHit.transform.position, player.transform.position);
- if ((objectHit == door) && (distance < 2)) // 1.32
- {
- // moveDirection = !moveDirection;
- doMove = true;
- print("Pressed, distance: " + distance);
- }
- }
- }
- void FixedUpdate()
- {
- if (doMove)
- {
- if (moveDirection == false) // close to open
- {
- transform.RotateAround(pivotPoint.transform.position, Vector3.up, 50 * Time.deltaTime);
- if (transform.rotation.y > 0.5)
- {
- doMove = false;
- moveDirection = true; // next movedir = open to close
- }
- }
- else if (moveDirection == true) // open to close
- {
- transform.RotateAround(pivotPoint.transform.position, -Vector3.up, 50 * Time.deltaTime);
- if (transform.rotation.y < 0.0)
- {
- doMove = false;
- moveDirection = false; // next movedir = close to open
- }
- }
- }
- }
- void OnGUI()
- {
- // Screen.lockCursor = true;
- Cursor.lockState = CursorLockMode.Locked;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement