Hi there,
I have a member variable ‘rotSpeed’ which I’m trying to assign a value to in a co-routine (before the while loop). This however seems to have no effect. Any ideas why? Perhaps I’m missing something simple.
Here’s my code (See lines 9 and 87):
using UnityEngine;
using System.Collections;
using System;
public class Player : MonoBehaviour {
Transform arrow;
public float rotSpeed = 20f // THIS MEMBER VARIABLE
public float boostLerpTime = 1;
public float boostFactor = 2;
bool rotatingRight = true;
public bool RotatingRight
{
get
{
return rotatingRight;
}
set
{
rotatingRight = value;
}
}
void Awake () {
arrow = transform.FindChild("Arrow");
if (arrow == null)
{
Debug.LogError(arrow + "object is null");
}
}
void Update () {
RotateArrow();
}
public void RotInputTrigger(bool RightSwipe)
{
if (RightSwipe && RotatingRight)
{
Debug.Log("Boost Right!");
StopCoroutine("ArrowSpeedBoost");
StartCoroutine("ArrowSpeedBoost");
}
else if (!RightSwipe && !RotatingRight)
{
Debug.Log("Boost Left!");
StopCoroutine("ArrowSpeedBoost");
StartCoroutine("ArrowSpeedBoost");
}
else if (RightSwipe && !RotatingRight)
{
rotatingRight = true;
}
else if (!RightSwipe && RotatingRight)
{
rotatingRight = false;
}
}
void RotateArrow()
{
if (RotatingRight)
{
arrow.Rotate(-transform.forward * rotSpeed * Time.deltaTime);
}
else
{
arrow.Rotate(transform.forward * rotSpeed * Time.deltaTime);
}
}
IEnumerator ArrowSpeedBoost()
{
float perc = 0;
float currentLerpTime = 0;
float initialRotSpeed = rotSpeed;
float boostedSpeed = rotSpeed * boostFactor;
rotSpeed = boostedSpeed; // This line seems to have no effect.
while (currentLerpTime < boostLerpTime)
{
Debug.Log("Boosting!!!");
currentLerpTime += Time.deltaTime;
perc = boostLerpTime / currentLerpTime;
rotSpeed = Mathf.Lerp(boostedSpeed, initialRotSpeed, perc);
yield return null;
}
}
}