Skip to content

Instantly share code, notes, and snippets.

@daemonfire300
Created April 23, 2013 21:07
Show Gist options
  • Save daemonfire300/5447403 to your computer and use it in GitHub Desktop.
Save daemonfire300/5447403 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
public class targetControl : MonoBehaviour
{
public bool targetControlEnabled = true;
public bool boost = false;
public int boostCount;
// Use this for initialization
void Start ()
{
boostCount = 0;
}
// Update is called once per frame
void Update ()
{
boost = (boostCount > 0);
if (targetControlEnabled) {
if (Input.GetKey ("left"))
rigidbody.AddForce (-2000F, 0, 0);
if (Input.GetKey ("right"))
rigidbody.AddForce (2000F, 0, 0);
if (Input.GetKey ("space") || Input.GetKey ("up"))
rigidbody.AddForce (0, 42000F, 0);
}
if (Input.GetKey ("0") && boost) {
rigidbody.AddForce (90000F, 0, 0);
boostCount--;
}
}
void OnTriggerEnter(Collider other){
if (other.gameObject.tag == "boost") {
Debug.Log("boosted");
Debug.Log(other);
boostCount++;
Destroy (other.gameObject);
}
}
void OnCollisionEnter (Collision collision)
{
if (collision.gameObject.tag == "floor") {
targetControlEnabled = true;
}
}
void OnCollisionExit (Collision collision)
{
if (collision.gameObject.tag == "floor") {
targetControlEnabled = false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment