public IEnumerator Move(int fuel, Card.Directions direction) { m_isMoving = true; currentDirection = direction; if (m_carFuel > 100) { m_carFuel = 100; } Debug.Log("current fuel is " + m_carFuel); Debug.Log("current direction is " + direction); GameManager.instance.soundManager.CarSound(direction); if (direction == Card.Directions.Straight) { while (fuel > 0) { transform.Translate(Vector3.forward * m_speed * Time.deltaTime); fuel--; m_carFuel--; Debug.Log("current fuel is " + m_carFuel); yield return(null); } } else { Vector3 rotation = DirectionAndFuelToVector3(fuel, direction); Vector3 newAngle = new Vector3(transform.eulerAngles.x + rotation.x, transform.eulerAngles.y + rotation.y, transform.eulerAngles.z + rotation.z); Vector3 currentAngle = transform.eulerAngles; float timer = 0f; float completion = 0f; while (completion <= 1) { timer += Time.deltaTime; completion = timer * m_turnSpeed; transform.eulerAngles = Vector3.Lerp(currentAngle, newAngle, completion); yield return(null); } Debug.Log("Finished turning"); m_carFuel -= fuel; fuel = 0; } m_isMoving = false; }
private Vector3 DirectionAndFuelToVector3(int fuel, Card.Directions direction) { Vector3 rotation = new Vector3(0, 0, 0); float fuelMath = fuel; fuelMath /= 100; if (direction == Card.Directions.Left) { rotation = new Vector3(0, -180 * fuelMath, 0); } else if (direction == Card.Directions.Right) { rotation = new Vector3(0, 180 * fuelMath, 0); } return(rotation); }
public void CarSound(Card.Directions dir = Card.Directions.None) { /* Disable for now * if (dir == Card.Directions.Straight) * { * racer.clip = CarStraight; * racer.Play(); * } * else if (dir == Card.Directions.Left || dir == Card.Directions.Right) * { * racer.clip = CarTurn; * racer.Play(); * } * else * { * racer.clip = CarCrash; * racer.Play(); * }*/ }