Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Controlador_Manos : MonoBehaviour
- {
- public bool tiene_tablilla = false;
- public bool puede_recoger_tablilla = false;
- public Transform posicion_manostablilla; // publico
- public Transform objeto_tablilla;
- public Vector3 offset;
- void recoger_tablilla ()
- {
- tiene_tablilla = true;
- objeto_tablilla.SetParent(posicion_manostablilla);
- objeto_tablilla.localPosition = new Vector3(0, 0, 0);
- }
- void colocar_tablilla ()
- {
- // var cam :
- RaycastHit hit;
- // Transform cam = Camera.main.transform;
- // if(Physics.Raycast (cam.position, cam.forward, out hit, 5000))
- if(Physics.Raycast (transform.position, transform.forward, out hit, 3.4f))
- {
- // Debug.Log("hi");
- // Debug.Log(hit.collider.gameObject);
- if (hit.normal.y > 0.75f) {
- tiene_tablilla = false;
- objeto_tablilla.parent = null;
- objeto_tablilla.position = hit.point;
- objeto_tablilla.position += offset;
- objeto_tablilla.rotation = Quaternion.identity;
- foreach (GameObject item in GameObject.FindGameObjectsWithTag("Puerta"))
- {
- float separacion = 0;
- separacion = (hit.point - item.transform.position).magnitude;
- if (item.GetComponent<Controlador_puerta>().max_distance > separacion) {
- item.GetComponent<Controlador_puerta>().Abrir_puerta();
- }
- }
- }
- }
- }
- // Start is called before the first frame update
- void Start()
- {
- }
- // Update is called once per frame
- void Update()
- {
- if (Input.GetMouseButtonDown(0))
- {
- if(tiene_tablilla == true){
- colocar_tablilla();
- }
- else if (tiene_tablilla == false && puede_recoger_tablilla == true) {
- recoger_tablilla();
- }
- }
- }
- private void OnTriggerEnter(Collider other)
- {
- if (other.gameObject.tag == "Tablilla")
- {
- puede_recoger_tablilla = true;
- objeto_tablilla = other.gameObject.transform;
- }
- }
- private void OnTriggerExit(Collider other)
- {
- if (other.gameObject.tag == "Tablilla")
- {
- puede_recoger_tablilla = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement