As of now, I'm getting a C# error (CS1624) stating that:
The body of PlayerMovement.Update() cannot be an iterator block because void is not an iterator interface type.
The error is within the void Update section
. I believe it started when I added lines 34 - 37, the second "if" clause.
Here's the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
Animator m_Animator;
bool m_Jump;
public CharacterController2D controller;
public float runSpeed = 40f;
float horizontalMove = 0f;
bool jump = false;
void Start()
{
m_Animator = gameObject.GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
if (Input.GetButtonDown("Jump"))
{
jump = true;
m_Animator.SetBool("Jump", true);
}
// These are lines 34-37 that cause the error, I think.
if (m_Animator.GetBool("Jump") == true)
{
yield return new WaitForSeconds(3);
m_Animator.SetBool("Jump", false);
}
}
void FixedUpdate()
{
controller.Move(horizontalMove * Time.fixedDeltaTime, false, jump);
jump = false;
}
}
yield return new WaitForSeconds(3);
won't work as the error says. And you do not want your update to pause for 3sec in the first place, your whole Character would stop responsding. \$\endgroup\$