Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Slingshot : MonoBehaviour {
- public GameObject ballPrefab;
- public GameObject slingGO;
- private Vector3 slingShotStart;
- private GameObject currBall;
- private bool ready = true;
- private SteamVR_TrackedObject trackedController;
- private bool inSlingShot = false;
- // Use this for initialization
- void Start () {
- slingShotStart = slingGO.transform.position;
- }
- // Update is called once per frame
- void Update ()
- {
- if (ready) {
- currBall = Instantiate (ballPrefab);
- currBall.transform.parent = slingGO.transform;
- currBall.transform.localPosition = Vector3.zero;
- ready = false;
- }
- if (inSlingShot) {
- slingGO.transform.position = trackedController.transform.position;
- }
- }
- void OnTriggerEnter (Collider other)
- {
- trackedController = other.GetComponent<SteamVR_TrackedObject> ();
- if (trackedController != null) {
- inSlingShot = true;
- }
- }
- void OnTriggerExit (Collider other)
- {
- trackedController = other.GetComponent<SteamVR_TrackedObject> ();
- if (trackedController != null) {
- inSlingShot = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement