This commit is contained in:
Patrice Vignola 2016-01-31 09:53:08 -05:00
parent da8d5a0506
commit fe98521b0d
3 changed files with 145 additions and 119 deletions

View File

@ -1,118 +1,118 @@
using UnityEngine; using UnityEngine;
using System.Collections; using System.Collections;
using System; using System;
[RequireComponent(typeof(Rigidbody))] [RequireComponent(typeof(Rigidbody))]
public class Character : MonoBehaviour public class Character : MonoBehaviour
{ {
public Animator animator; public Animator animator;
public float MoveSpeed; public float MoveSpeed;
public float TurnSpeed; public float TurnSpeed;
public float DashForce; public float DashForce;
public float DashCooldown; public float DashCooldown;
public Color TrailColor; public Color TrailColor;
private Rigidbody rb; private Rigidbody rb;
private Quaternion targetRot = Quaternion.identity; private Quaternion targetRot = Quaternion.identity;
private float dashRemainingTime = 6f; private float dashRemainingTime = 6f;
private bool isDashing = false; private bool isDashing = false;
private int playerId; private int playerId;
private SelectorWithBolts selector; private SelectorWithBolts selector;
private Vector3 dashForward; private Vector3 dashForward;
private ParticleSystem particleSys; private ParticleSystem particleSys;
public int PlayerID public int PlayerID
{ {
get { return playerId; } get { return playerId; }
set { playerId = value; } set { playerId = value; }
} }
void Awake() void Awake()
{ {
rb = GetComponent<Rigidbody>(); rb = GetComponent<Rigidbody>();
particleSys = GetComponent<ParticleSystem>(); particleSys = GetComponent<ParticleSystem>();
} }
void Start() void Start()
{ {
selector = GameObject.FindObjectOfType<SelectorWithBolts>(); selector = GameObject.FindObjectOfType<SelectorWithBolts>();
} }
void Update() void Update()
{ {
if (dashRemainingTime > 0) if (dashRemainingTime > 0)
{
dashRemainingTime = Mathf.Clamp(dashRemainingTime - Time.deltaTime, 0f, DashCooldown);
}
if (isDashing)
{
rb.AddForce(dashForward * DashForce, ForceMode.VelocityChange);
}
else
{ {
rb.rotation = Quaternion.RotateTowards(rb.rotation, targetRot, TurnSpeed * Time.deltaTime); dashRemainingTime = Mathf.Clamp(dashRemainingTime - Time.deltaTime, 0f, DashCooldown);
} }
}
if (isDashing)
public void Move(float xValue, float zValue) {
{ rb.AddForce(dashForward * DashForce, ForceMode.VelocityChange);
if (isDashing) return; }
else
Vector3 forwardDir = Camera.main.transform.forward; {
Vector3 rightDir = Camera.main.transform.right; rb.rotation = Quaternion.RotateTowards(rb.rotation, targetRot, TurnSpeed * Time.deltaTime);
}
forwardDir.y = 0f; }
forwardDir = forwardDir.normalized * zValue;
public void Move(float xValue, float zValue)
rightDir.y = 0f; {
rightDir = rightDir.normalized * xValue; if (isDashing) return;
Vector3 newVelocity = (forwardDir + rightDir) * MoveSpeed; Vector3 forwardDir = Camera.main.transform.forward;
Vector3 rightDir = Camera.main.transform.right;
if (newVelocity != Vector3.zero)
{ forwardDir.y = 0f;
// We rotate to face the new direction forwardDir = forwardDir.normalized * zValue;
targetRot = Quaternion.LookRotation(newVelocity.normalized);
} rightDir.y = 0f;
rightDir = rightDir.normalized * xValue;
newVelocity.y = rb.velocity.y;
Vector3 newVelocity = (forwardDir + rightDir) * MoveSpeed;
rb.velocity = newVelocity;
animator.SetFloat("Walk", rb.velocity.magnitude); if (newVelocity != Vector3.zero)
} {
// We rotate to face the new direction
public bool Dash() targetRot = Quaternion.LookRotation(newVelocity.normalized);
{ }
if (dashRemainingTime > 0f) return false;
newVelocity.y = rb.velocity.y;
selector.ReplenishPlayerDashMeter(playerId);
rb.velocity = newVelocity;
dashRemainingTime = DashCooldown; animator.SetFloat("Walk", rb.velocity.magnitude);
}
//particleSys.Play();
public bool Dash()
StartCoroutine(DashCoroutine()); {
if (dashRemainingTime > 0f) return false;
return true;
} selector.ReplenishPlayerDashMeter(playerId);
private IEnumerator DashCoroutine() dashRemainingTime = DashCooldown;
{
isDashing = true; //particleSys.Play();
dashForward = GetComponent<Transform>().forward; StartCoroutine(DashCoroutine());
rb.velocity = Vector3.zero;
return true;
animator.SetTrigger("Dash"); }
yield return new WaitForSeconds(0.9f); private IEnumerator DashCoroutine()
{
isDashing = false; isDashing = true;
}
} dashForward = GetComponent<Transform>().forward;
rb.velocity = Vector3.zero;
animator.SetTrigger("Dash");
yield return new WaitForSeconds(0.9f);
isDashing = false;
}
}

View File

@ -72,8 +72,12 @@ public class RuneBehaviour : MonoBehaviour {
while (ratio < 1f) while (ratio < 1f)
{ {
ratio += Time.deltaTime / LightTime; // Hack
symbol.color = Color.Lerp(startColor, DefaultColor, ratio); if (enabled)
{
ratio += Time.deltaTime / LightTime;
symbol.color = Color.Lerp(startColor, DefaultColor, ratio);
}
yield return null; yield return null;
} }

View File

@ -1,5 +1,6 @@
using UnityEngine; using UnityEngine;
using System.Collections; using System.Collections;
using XInputDotNetPure;
[RequireComponent(typeof(Rigidbody))] [RequireComponent(typeof(Rigidbody))]
public class SelectorWithBolts : MonoBehaviour public class SelectorWithBolts : MonoBehaviour
@ -74,5 +75,26 @@ public class SelectorWithBolts : MonoBehaviour
yield return null; yield return null;
} }
StartCoroutine(VibrateController(playerId));
}
private IEnumerator VibrateController(int playerId)
{
GamePad.SetVibration((PlayerIndex)playerId, 1f, 1f);
yield return new WaitForSeconds(0.5f);
GamePad.SetVibration((PlayerIndex)playerId, 0f, 0f);
}
void OnApplicationQuit()
{
// In case the coroutine was still running when we closed the game
for (int i = 0; i < Bolts.Length; i++)
{
GamePad.SetVibration((PlayerIndex)i, 0f, 0f);
}
} }
} }