Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | None | 0 0
  1.  
  2. public class Iteraction : Base_Gameplay
  3. {
  4.     private Iteraction useItem;
  5.     private Iteraction takeItem;
  6.  
  7.     protected ObjectOfType type;
  8.  
  9.     public GameObject TakeUIButton;
  10.     public GameObject UseUIButton;
  11.  
  12.     void Start()
  13.     {
  14.         useItem = new UseItem();
  15.         takeItem = new TakeItem();
  16.     }
  17.  
  18.     void Update()
  19.     {
  20.         Vector3 fwd = transform.TransformDirection(Vector3.forward);
  21.         RaycastHit hit;
  22.  
  23.         if (Physics.Raycast(transform.position, fwd, out hit, 3))
  24.         {
  25.             if(hit.collider.gameObject.tag == "Item")
  26.             {
  27.                 type = hit.collider.gameObject.GetComponent<ObjectOfType>();
  28.  
  29.                 if (type.type == ObjectOfType.Type.Button)
  30.                 {
  31.                     UseUIButton.SetActive(true);
  32.  
  33.                    #if UNITY_EDITOR
  34.                     if(Input.GetKeyDown(KeyCode.E))
  35.                         useItem.Use();
  36.                    #endif
  37.  
  38.                 }
  39.  
  40.                 if (type.type == ObjectOfType.Type.Battery ||type.type == ObjectOfType.Type.Keys ||type.type == ObjectOfType.Type.Note)
  41.                 {
  42.                     TakeUIButton.SetActive(true);
  43.  
  44.                    #if UNITY_EDITOR
  45.                     if(Input.GetKeyDown(KeyCode.E))
  46.                         takeItem.Take();
  47.                    #endif
  48.                  
  49.                 }
  50.             }
  51.             else
  52.             {
  53.                 UseUIButton.SetActive(false);
  54.                 TakeUIButton.SetActive(false);
  55.             }
  56.            
  57.         }
  58.  
  59.     }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement