Advertisement
Guest User

slingshot

a guest
Jun 19th, 2016
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Slingshot : MonoBehaviour {
  5.  
  6. public GameObject ballPrefab;
  7.  
  8. public GameObject slingGO;
  9.  
  10. private Vector3 slingShotStart;
  11.  
  12. private GameObject currBall;
  13. private bool ready = true;
  14.  
  15. private SteamVR_TrackedObject trackedController;
  16. private bool inSlingShot = false;
  17.  
  18. // Use this for initialization
  19. void Start () {
  20. slingShotStart = slingGO.transform.position;
  21. }
  22.  
  23. // Update is called once per frame
  24. void Update ()
  25. {
  26. if (ready) {
  27. currBall = Instantiate (ballPrefab);
  28. currBall.transform.parent = slingGO.transform;
  29. currBall.transform.localPosition = Vector3.zero;
  30. ready = false;
  31. }
  32. if (inSlingShot) {
  33. slingGO.transform.position = trackedController.transform.position;
  34. }
  35. }
  36.  
  37. void OnTriggerEnter (Collider other)
  38. {
  39. trackedController = other.GetComponent<SteamVR_TrackedObject> ();
  40. if (trackedController != null) {
  41. inSlingShot = true;
  42. }
  43. }
  44. void OnTriggerExit (Collider other)
  45. {
  46. trackedController = other.GetComponent<SteamVR_TrackedObject> ();
  47. if (trackedController != null) {
  48. inSlingShot = false;
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement