Skip to content

Instantly share code, notes, and snippets.

@joshalanwagner
Created September 22, 2015 19:10
Show Gist options
  • Select an option

  • Save joshalanwagner/a7915cc5c9c35510714a to your computer and use it in GitHub Desktop.

Select an option

Save joshalanwagner/a7915cc5c9c35510714a to your computer and use it in GitHub Desktop.
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