- Home /
Weird Error c#
void FixedUpdate ()
{
float h = Input.GetAxis("Horizontal"); // setup h variable as our horizontal input axis
float v = Input.GetAxis("Vertical"); // setup v variables as our vertical input axis
anim.SetFloat("Speed", v); // set our animator's float parameter 'Speed' equal to the vertical input axis
anim.SetFloat("Direction", h); // set our animator's float parameter 'Direction' equal to the horizontal input axis
anim.speed = animSpeed; // set the speed of our animator to the public variable 'animSpeed'
anim.SetLookAtWeight(lookWeight); // set the Look At Weight - amount to use look at IK vs using the head's animation
currentBaseState = anim.GetCurrentAnimatorStateInfo(0); // set our currentState variable to the current state of the Base Layer (0) of animation
if(anim.layerCount ==2)
layer2CurrentState = anim.GetCurrentAnimatorStateInfo(1); // set our layer2CurrentState variable to the current state of the second Layer (1) of animation
// LOOK AT ENEMY
// if we hold Alt..
if(Input.GetButton("Fire2"))
{
// ...set a position to look at with the head, and use Lerp to smooth the look weight from animation to IK (see line 54)
anim.SetLookAtPosition(enemy.position);
lookWeight = Mathf.Lerp(lookWeight,1f,Time.deltaTime*lookSmoother);
}
// else, return to using animation for the head by lerping back to 0 for look at weight
else
{
lookWeight = Mathf.Lerp(lookWeight,0f,Time.deltaTime*lookSmoother);
}
// STANDARD JUMPING
// if we are currently in a state called Locomotion (see line 25), then allow Jump input (Space) to set the Jump bool parameter in the Animator to true
if (currentBaseState.nameHash == locoState)
{
if(Input.GetKeyDown("left ctrl"))
{
anim.SetBool("Roll", true);
yield return new WaitForSeconds(2);
anim.SetBool("Roll", false);
}
if(Input.GetKey("left shift"))
{
anim.SetBool("Jump", true);
}
}
}
Says That The body of BotControlScript.FixedUpdate()' cannot be an iterator block because
void' is not an iterator interface type But Just 3 seconds ago It Wasnt There... Please Help
Comment
Best Answer
Answer by clunk47 · Sep 07, 2013 at 06:54 PM
It's because you're using yield inside of FixedUpdate(). You can't do this in FixedUpdate() or Update(), you must use a Coroutine, which will likely be an IEnumerator function.
C# Example of a coroutine:
IEnumerator MyCoroutine()
{
yield return new WaitForSeconds(3);
print("Coroutine Done!");
}
//Another example, to loop through the coroutine.
IEnumerator MyLoopingCoroutine()
{
int count = 0;
while(true)
{
yield return new WaitForSeconds(1);
count++;
print(count);
}
}
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Please Help 1 Answer
Multiple Cars not working 1 Answer
Error CS0023: The '!' operator cannot be applied to operand of type 'void' 1 Answer
Help please guys thank you so much! 1 Answer