Advertisement
Diamond32_Tutoriales

Sistema de Coger Carta

Aug 5th, 2020 (edited)
1,886
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.63 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityStandardAssets.Characters.FirstPerson;
  5.  
  6. public class Pergamino : MonoBehaviour {
  7.     public Transform PosNewPergamino;
  8.     public Transform PosAntigua;
  9.  
  10.     public bool PergaminoTomado = false;
  11.     public FirstPersonController fps;
  12.  
  13.     void Start () {
  14.         PergaminoTomado = false;
  15.     }
  16.    
  17.     void Update () {
  18.         fps = GameObject.FindGameObjectWithTag ("Player").GetComponent<FirstPersonController>();
  19.  
  20.         PosNewPergamino = GameObject.Find ("PergaminoTomado").GetComponent<Transform> ();
  21.  
  22.         if (PergaminoTomado){
  23.             transform.Rotate (Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"), 0);
  24.         }
  25.  
  26.  
  27.  
  28.         if (PergaminoTomado && Input.GetKeyDown(KeyCode.Mouse0)) {
  29.             PergaminoTomado = false;
  30.             transform.SetParent (null);
  31.             fps.enabled = true;
  32.  
  33.             transform.localPosition = new Vector3 (PosAntigua.position.x,
  34.                 PosAntigua.position.y,
  35.                 PosAntigua.position.z);
  36.  
  37.             transform.localRotation = Quaternion.Euler (-90,0,0);
  38.         }
  39.     }
  40.  
  41.     public void CogerPergamino () {
  42.         if (!PergaminoTomado) {
  43.             transform.localPosition = new Vector3 (PosNewPergamino.position.x,
  44.                 PosNewPergamino.position.y,
  45.                 PosNewPergamino.position.z);
  46.             transform.localRotation = Quaternion.Euler (0,0,0);
  47.             transform.SetParent (PosNewPergamino);
  48.             fps.enabled = false;
  49.             StartCoroutine(cogido());
  50.         }
  51.     }
  52.  
  53.  
  54.     IEnumerator cogido () {
  55.         yield return new WaitForSeconds (0.00001f);
  56.  
  57.         transform.localPosition = new Vector3 (0, 0, 0);
  58.         transform.localRotation = Quaternion.Euler (0,0,0);
  59.         transform.localScale = new Vector3 (1, 1, 1);
  60.         PergaminoTomado = true;
  61.     }
  62. }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement