Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityStandardAssets.Characters.FirstPerson;
  6.  
  7. public class door : MonoBehaviour
  8. {
  9.     public GameObject exitLocation;
  10.     internal UnityEngine.Vector3 exit_pos;
  11.     internal UnityEngine.Quaternion exit_rot;
  12.     internal FirstPersonController player;
  13.     internal TalkieBox tb_script;
  14.     internal string[] text;
  15.  
  16.     void Start()
  17.     {
  18.         exit_pos[0] = gameObject.transform.position.x;
  19.         exit_pos[1] = gameObject.transform.position.y;
  20.         exit_pos[2] = gameObject.transform.position.z + 0.2f;
  21.  
  22.         exit_rot[0] = gameObject.transform.rotation.x;
  23.         exit_rot[1] = gameObject.transform.rotation.y;
  24.         exit_rot[2] = gameObject.transform.rotation.z;
  25.  
  26.         player = GameObject.FindObjectOfType(typeof(FirstPersonController)) as FirstPersonController;
  27.         tb_script = GameObject.FindObjectOfType(typeof(TalkieBox)) as TalkieBox;
  28.     }
  29.  
  30.     void OnMouseOver()
  31.     {
  32.         if (Input.GetMouseButtonDown(0))
  33.         {
  34.             if (exitLocation.GetComponent<door>())
  35.             {
  36.                 player.gameObject.transform.parent.position = exitLocation.transform.parent.position;
  37.                 player.gameObject.transform.parent.rotation = exitLocation.transform.parent.rotation;
  38.             }
  39.             else
  40.             {
  41.                 text = new string[] {
  42.                     "This door is locked."
  43.                 };
  44.                 tb_script.UpdateDialog(text);
  45.             }
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement