-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using UnityEngine; | ||
using System.Collections; | ||
|
||
public class PlayerBar : HUDBase | ||
{ | ||
private GameObject PlayerBarObject; | ||
private Transform PlayerBarTransform; | ||
|
||
private GUIText myName; | ||
public Font TextFont; | ||
public int FontSize = 20; | ||
GUIStyle TextStyle; | ||
|
||
private Transform target; | ||
public Vector3 heightOffset = Vector3.up; // Put it to one unit above the player for now | ||
public bool clampToScreen = false; // if true the label will be visible even when the player it out of the frame | ||
public float clampBorderSize = 0.05f; // How much viewport space to leave at the borders when label is clamped | ||
|
||
private Camera cam; | ||
private Transform camTransform; | ||
|
||
void Awake() | ||
{ | ||
// Disable playerbar for our own car | ||
if (Player.IsLocalPlayer) | ||
this.enabled = false; | ||
} | ||
|
||
void Start() | ||
{ | ||
PlayerBarObject = new GameObject("PlayerBar"); | ||
PlayerBarTransform = PlayerBarObject.transform; | ||
myName = (GUIText)PlayerBarObject.AddComponent(typeof(GUIText)); | ||
myName.text = Player.Name; | ||
myName.font = TextFont; | ||
myName.fontSize = FontSize; | ||
|
||
cam = Camera.main; | ||
camTransform = cam.transform; | ||
|
||
// our target is the transform of the car | ||
target = transform.GetComponentInChildren<CarHandling> ().transform; | ||
} | ||
|
||
// Update is called once per frame | ||
void Update () | ||
{ | ||
} | ||
|
||
|
||
void OnGUI() | ||
{ | ||
PlayerBarTransform.position = cam.WorldToViewportPoint (target.position + heightOffset); | ||
if (PlayerBarTransform.position.z < 0) | ||
PlayerBarObject.SetActive (false); | ||
else | ||
PlayerBarObject.SetActive (true); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using UnityEngine; | ||
using System.Collections; | ||
|
||
public abstract class AimSkill : Skill { | ||
|
||
private bool isAiming; | ||
|
||
// Use this for initialization | ||
void Start () | ||
{ | ||
isAiming = false; | ||
} | ||
|
||
// Update is called once per frame | ||
void Update () | ||
{ | ||
listenForFire(); | ||
} | ||
|
||
/// <summary> | ||
/// Wrapper function around the abstract aim function to make sure that all skills follow the cooldown | ||
/// </summary> | ||
private void aim() | ||
{ | ||
if (isReady) | ||
{ | ||
isAiming = true; | ||
_aim(); | ||
} | ||
} | ||
|
||
private void stopAiming() | ||
{ | ||
isAiming = false; | ||
_stopAiming(); | ||
} | ||
|
||
private void listenForFire() | ||
{ | ||
if (isAiming && Input.GetButtonUp(Constants.KEY_MAIN_FIRE)) | ||
{ | ||
applyCooldown(); | ||
stopAiming(); | ||
_fire(); | ||
} | ||
} | ||
|
||
protected override void ButtonPressed() | ||
{ | ||
aim(); | ||
} | ||
|
||
protected override void ButtonReleased() | ||
{ | ||
stopAiming(); | ||
} | ||
|
||
protected abstract void _aim(); | ||
protected abstract void _stopAiming(); | ||
protected abstract void _fire(); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
using UnityEngine; | ||
using System.Collections; | ||
|
||
|
||
public abstract class Skill : SkillBase | ||
{ | ||
public float cooldown = 2F; // The time it takes the skill to recharge | ||
|
||
public Button Button; | ||
|
||
private float _currentCooldown; | ||
public float CurrentCooldown | ||
{ | ||
get | ||
{ | ||
return _currentCooldown; | ||
} | ||
} | ||
|
||
private bool _isReady; | ||
public bool isReady | ||
{ | ||
get | ||
{ | ||
return _isReady; | ||
} | ||
} | ||
|
||
//TODO: | ||
// Add icon to draw in the HUD | ||
|
||
protected void Start() | ||
{ | ||
_isReady = true; | ||
_currentCooldown = 0.0f; | ||
} | ||
|
||
/// <summary> | ||
/// Each update we check if our button has been pressed | ||
/// </summary> | ||
protected void Update() | ||
{ | ||
// Check if the button is being pressed OBS: DO THIS BETTER .TOSTRING IS EXPENSIVE!!!!!!!!!!!!!!! | ||
if (Input.GetButtonDown(Button.ToString())) | ||
{ | ||
Debug.Log("BUTTON DOWN"); | ||
ButtonPressed(); | ||
} | ||
else if (Input.GetButtonUp(Button.ToString())) | ||
{ | ||
Debug.Log("BUTTON UP"); | ||
ButtonReleased(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Starts thte coroutine that performs the cooldown | ||
/// </summary> | ||
protected void applyCooldown() | ||
{ | ||
Debug.Log("APPLYING CD"); | ||
_isReady = false; | ||
_currentCooldown = cooldown; | ||
StartCoroutine(countdown()); | ||
} | ||
|
||
/// <summary> | ||
/// Counts down until the cooldown has passed | ||
/// </summary> | ||
/// <returns></returns> | ||
private IEnumerator countdown() | ||
{ | ||
while (_currentCooldown > 0.0F) | ||
{ | ||
Debug.Log("_currentCoolDown = " + _currentCooldown); | ||
_currentCooldown -= Time.deltaTime; | ||
yield return null; | ||
} | ||
|
||
Debug.Log("After While"); | ||
_isReady = true; | ||
} | ||
|
||
protected abstract void ButtonPressed(); | ||
protected abstract void ButtonReleased(); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.