Guest User

Untitled

a guest
Jul 22nd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Playables;
  5.  
  6. public class SpaceshipCutscene : MonoBehaviour
  7. {
  8. public Transform player;
  9. public Transform[] npcs;
  10. public Transform console;
  11. public Camera FPSCamera;
  12. public Camera mainCamera;
  13. public Animator[] anim;
  14. public float rotationSpeed = 3f;
  15.  
  16. private bool moveNpc = false;
  17.  
  18. // Use this for initialization
  19. void Start()
  20. {
  21.  
  22. }
  23.  
  24. private void Update()
  25. {
  26. if (moveNpc)
  27. {
  28. // Soldier 2 rotating and looking at player
  29. Vector3 dir = player.position - npcs[0].position;
  30. dir.y = 0; // keep the direction strictly horizontal
  31. Quaternion rot = Quaternion.LookRotation(dir);
  32. // slerp to the desired rotation over time
  33. npcs[0].rotation = Quaternion.Slerp(npcs[0].rotation, rot, rotationSpeed * Time.deltaTime);
  34.  
  35. Vector3 dirToComputer = console.transform.position - npcs[1].position;
  36. dirToComputer.y = 0;
  37. Quaternion rot1 = Quaternion.LookRotation(dirToComputer);
  38. npcs[1].rotation = Quaternion.Slerp(npcs[1].rotation, rot1, rotationSpeed * Time.deltaTime);
  39. }
  40. }
  41.  
  42. private void OnTriggerExit(Collider other)
  43. {
  44. if (other.gameObject.tag == "SpaceshipCutscene")
  45. {
  46. FPSCamera.enabled = false;
  47. mainCamera.enabled = true;
  48. moveNpc = true;
  49. anim[0].SetTrigger("SoldierAimingTrigger");
  50. anim[1].SetTrigger("SoldierWalkingTrigger");
  51. }
  52. }
  53. }
Add Comment
Please, Sign In to add comment