Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class DoorEntity : MonoBehaviour {
  5.  
  6.  
  7.     //private:
  8.     private GameObject player;
  9.     private RaycastHit hit;
  10.  
  11.     //Rect:
  12.     float sizex = 100;
  13.     float sizey = 50;
  14.     private Rect r1;
  15.     //endrect
  16.  
  17.     private bool isLooking = false;
  18.     private float angle = 0;
  19.  
  20.  
  21.     void Start ()
  22.     {
  23.         player = GameObject.FindGameObjectWithTag("Player");
  24.         r1 = new Rect ((Screen.width/2 - sizex/2),(Screen.height/2 - sizey/2), sizex, sizey);      
  25.     }
  26.    
  27.  
  28.     void Update ()
  29.     {  
  30.        
  31.         Vector3 forward = player.transform.TransformDirection(Vector3.forward);
  32.  
  33.         if(Physics.Raycast(player.transform.position, forward, out hit, 1.5f))
  34.         {          
  35.             isLooking = true;
  36.             if(Input.GetKeyDown(KeyCode.F))        
  37.                     StartCoroutine(Open(hit.transform.gameObject));
  38.            
  39.         }
  40.  
  41.         else
  42.             isLooking = false;         
  43.        
  44.     }
  45.    
  46.     void OnGUI()
  47.     {
  48.         if (isLooking)
  49.         {          
  50.             GUI.Button (r1, "Press F");
  51.         }
  52.     }
  53.  
  54.     IEnumerator Open(GameObject door)
  55.     {
  56.         while (angle<91)
  57.         {
  58.             yield return new WaitForSeconds(0.01f);
  59.             door.gameObject.transform.Rotate(Vector3.forward,1);
  60.             angle++;
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement