Created
September 22, 2015 19:10
-
-
Save joshalanwagner/a7915cc5c9c35510714a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| using System.Collections; | |
| using UnityEngine.UI; | |
| public class Ball : MonoBehaviour { | |
| //public float initialForce = 20.0f; | |
| public Vector3 launchVelocity; | |
| public bool ballLoaded; | |
| private Rigidbody rgdbdy; | |
| private AudioSource ballSound; | |
| private float laneWidth; | |
| private GameObject slider; | |
| void Awake () | |
| { | |
| rgdbdy = gameObject.GetComponent<Rigidbody>(); | |
| rgdbdy.useGravity = false; | |
| slider = GameObject.Find("BallSlider"); | |
| laneWidth = GameObject.Find("Lane").transform.localScale.x; | |
| } | |
| void Start () | |
| { | |
| ballLoaded = true; | |
| } | |
| public void Nudge () | |
| { | |
| if (ballLoaded) | |
| { | |
| float value = slider.GetComponent<Slider>().value; | |
| float xPos = value * laneWidth / 2.0f ; | |
| transform.position = new Vector3 (xPos, transform.position.y, transform.position.z); | |
| } | |
| } | |
| public void Launch (Vector3 velocity) | |
| { | |
| if (ballLoaded) | |
| { | |
| rgdbdy.useGravity = true; | |
| rgdbdy.velocity = velocity; | |
| ballSound = GetComponent<AudioSource>(); | |
| ballSound.Play (); // should be in on collision enter? or add a delay. | |
| ballLoaded = false; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment