Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class CrosshairScript : MonoBehaviour
- {
- public Texture2D crosshairTexture;
- public int speed;
- public float friction;
- public float lerpSpeed;
- public float xDeg;
- public float yDeg;
- public Quaternion fromRotation;
- public Quaternion toRotation;
- void Start()
- {
- Cursor.visible = false;
- }
- void Update()
- {
- Ray ray = Camera.main.ScreenPointToRay(new Vector2 (Screen.width/2, Screen.height/2));
- RaycastHit hit;
- if(Physics.Raycast(ray, out hit, 10))
- {
- if (hit.collider.tag == "Bookcase_door")
- {
- if (Input.GetMouseButton(0))
- {
- if(Input.GetAxis("Mouse X") > 0)
- {
- Debug.Log(Input.GetAxis("Mouse X"));
- //xDeg -= Input.GetAxis("Mouse X") * speed * friction;
- yDeg += Input.GetAxis("Mouse Y") * speed * friction;
- fromRotation = hit.transform.rotation;
- toRotation = Quaternion.Euler(0, yDeg, 0);
- hit.transform.rotation = Quaternion.Lerp(fromRotation, toRotation, Time.deltaTime * lerpSpeed);
- }
- else if(Input.GetAxis("Mouse X") < 0)
- {
- Debug.Log(Input.GetAxis("Mouse X"));
- //xDeg -= Input.GetAxis("Mouse X") * speed * friction;
- yDeg -= Input.GetAxis("Mouse Y") * speed * friction;
- fromRotation = hit.transform.rotation;
- toRotation = Quaternion.Euler(0, yDeg, 0);
- hit.transform.rotation = Quaternion.Lerp(fromRotation, toRotation, Time.deltaTime * lerpSpeed);
- }
- }
- }
- else if (hit.collider.tag == "Door")
- {
- if (Input.GetMouseButton(0))
- {
- Debug.Log("Clicked Bookcase Door!");
- xDeg -= Input.GetAxis("Mouse X") * speed * friction;
- //yDeg += Input.GetAxis("Mouse Y") * speed * friction;
- fromRotation = hit.transform.rotation;
- toRotation = Quaternion.Euler(0, xDeg, 0);
- hit.transform.rotation = Quaternion.Lerp(fromRotation, toRotation, Time.deltaTime * lerpSpeed);
- }
- }
- }
- }
- void OnGUI()
- {
- GUI.DrawTexture(new Rect(Screen.width / 2-4, Screen.height / 2-4, 8, 8), crosshairTexture);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement