Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.57 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Controlador_Manos : MonoBehaviour
  6. {
  7.     public bool tiene_tablilla = false;
  8.     public bool puede_recoger_tablilla = false;
  9.  
  10.     public Transform posicion_manostablilla; // publico
  11.     public Transform objeto_tablilla;
  12.  
  13.     public Vector3 offset;
  14.  
  15.     void recoger_tablilla ()
  16.     {
  17.         tiene_tablilla = true;
  18.         objeto_tablilla.SetParent(posicion_manostablilla);
  19.         objeto_tablilla.localPosition = new Vector3(0, 0, 0);
  20.     }
  21.  
  22.     void colocar_tablilla ()
  23.     {
  24.         // var cam :
  25.         RaycastHit hit;
  26.         // Transform cam = Camera.main.transform;
  27.         // if(Physics.Raycast (cam.position, cam.forward, out hit, 5000))
  28.         if(Physics.Raycast (transform.position, transform.forward, out hit, 3.4f))
  29.         {
  30.             // Debug.Log("hi");
  31.             // Debug.Log(hit.collider.gameObject);
  32.  
  33.             if (hit.normal.y > 0.75f) {
  34.                 tiene_tablilla = false;
  35.                 objeto_tablilla.parent = null;
  36.                 objeto_tablilla.position = hit.point;
  37.                 objeto_tablilla.position += offset;
  38.                 objeto_tablilla.rotation = Quaternion.identity;
  39.  
  40.                 foreach (GameObject item in GameObject.FindGameObjectsWithTag("Puerta"))
  41.                 {
  42.                     float separacion = 0;
  43.                     separacion = (hit.point - item.transform.position).magnitude;
  44.                     if (item.GetComponent<Controlador_puerta>().max_distance > separacion) {
  45.                         item.GetComponent<Controlador_puerta>().Abrir_puerta();
  46.                     }
  47.                 }
  48.             }
  49.         }
  50.     }
  51.  
  52.     // Start is called before the first frame update
  53.     void Start()
  54.     {
  55.        
  56.     }
  57.  
  58.     // Update is called once per frame
  59.     void Update()
  60.     {
  61.         if (Input.GetMouseButtonDown(0))
  62.         {
  63.  
  64.           if(tiene_tablilla == true){
  65.               colocar_tablilla();
  66.           }  
  67.           else if (tiene_tablilla == false && puede_recoger_tablilla == true) {
  68.               recoger_tablilla();
  69.           }
  70.         }
  71.     }
  72.  
  73.     private void OnTriggerEnter(Collider other)
  74.     {
  75.         if (other.gameObject.tag == "Tablilla")
  76.         {
  77.             puede_recoger_tablilla = true;
  78.             objeto_tablilla        = other.gameObject.transform;
  79.         }
  80.     }
  81.  
  82.     private void OnTriggerExit(Collider other)
  83.     {
  84.         if (other.gameObject.tag == "Tablilla")
  85.         {
  86.            puede_recoger_tablilla = false;
  87.         }
  88.     }
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement