Advertisement
Guest User

carManager

a guest
Jun 28th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityStandardAssets.Vehicles.Car;
  5.  
  6. public class carManager : MonoBehaviour
  7. {
  8. public Camera carCam;
  9. public CarUserControl userCtrl;
  10. public GameObject VladInsideCar;
  11. public GameObject GabrielaInsideCar;
  12. public GameObject AlinInsideCar;
  13.  
  14.  
  15. private bool inVeh;
  16. private GameObject player;
  17.  
  18. void Start()
  19. {
  20. userCtrl.enabled = false;
  21. carCam.enabled = false;
  22. VladInsideCar.SetActive(false);
  23. GabrielaInsideCar.SetActive(false);
  24. AlinInsideCar.SetActive(false);
  25.  
  26. inVeh = false;
  27. }
  28.  
  29. void Update()
  30. {
  31. if (Input.GetKeyDown(KeyCode.F))
  32. {
  33. if (inVeh == true)
  34. {
  35. VehicleControl(null);
  36. }
  37. }
  38. }
  39.  
  40. public void VehicleControl(GameObject playerObj)
  41. {
  42. if (inVeh == false)
  43. {
  44. if (playerObj.tag == "Vlad")
  45. {
  46. player = playerObj;
  47. carCam.enabled = true;
  48. userCtrl.enabled = true;
  49. VladInsideCar.SetActive(true);
  50. player.SetActive(false);
  51. player.transform.parent = this.transform;
  52.  
  53. StartCoroutine(Time(true));
  54. }
  55.  
  56. else
  57.  
  58. if (playerObj.tag == "Gabriela")
  59. {
  60. player = playerObj;
  61. carCam.enabled = true;
  62. userCtrl.enabled = true;
  63. GabrielaInsideCar.SetActive(true);
  64. player.SetActive(false);
  65. player.transform.parent = this.transform;
  66.  
  67. StartCoroutine(Time(true));
  68. }
  69.  
  70. else
  71.  
  72. if (playerObj.tag == "Alin")
  73. {
  74. player = playerObj;
  75. carCam.enabled = true;
  76. userCtrl.enabled = true;
  77. AlinInsideCar.SetActive(true);
  78. player.SetActive(false);
  79. player.transform.parent = this.transform;
  80.  
  81. StartCoroutine(Time(true));
  82. }
  83.  
  84. }
  85. else
  86. {
  87. player.SetActive(true);
  88. carCam.enabled = false;
  89. VladInsideCar.SetActive(false);
  90. GabrielaInsideCar.SetActive(false);
  91. AlinInsideCar.SetActive(false);
  92. userCtrl.enabled = false;
  93. player.transform.parent = null;
  94. player = null;
  95.  
  96. StartCoroutine(Time(false));
  97. }
  98. }
  99.  
  100. private IEnumerator Time(bool inVehicle)
  101. {
  102. yield return new WaitForSeconds(1);
  103. inVeh = inVehicle;
  104. }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement