Created
April 23, 2013 21:07
-
-
Save daemonfire300/5447403 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; | |
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