I’m trying to call this Coroutine and its not working no matter what I do. It gives off a CS1503 and I have absolutely no clue how to fix it. I’ve tried numerus things and nothing has worked this far.
Here’s the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
[Header("Movement Settings")]
[SerializeField] float moveSpeed = 5f;
[SerializeField] float rotationSpeed = 500f;
[SerializeField] float jumpHeight = 5f;
/* set radius for ground check */
[Header("Ground Check Settings")]
[SerializeField] float groundCheckRadius = 0.2f;
[SerializeField] Vector3 groundCheckOffset;
[SerializeField] LayerMask groundLayer;
bool inAction;
bool isGrounded;
float ySpeed;
Quaternion targetRotation;
CameraController cameraController;
Animator animator;
CharacterController characterController;
private void Awake()
{
cameraController = Camera.main.GetComponent<CameraController>();
animator = GetComponent<Animator>();
characterController = GetComponent<CharacterController>();
}
private void Update()
{
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
float moveAmount = Mathf.Clamp01(Mathf.Abs(h) + Mathf.Abs(v));
var moveInput = (new Vector3(h, 0, v)).normalized;
var moveDir = cameraController.PlanarRotation * moveInput;
var velocity = moveDir * moveSpeed;
velocity.y = ySpeed;
if(Input.GetButtonDown("Jump") && !inAction)
{
StartCoroutine(DoJumpAnimation());
ySpeed = jumpHeight;
}
GroundCheck();
if (isGrounded)
{
ySpeed = -0.5f;
}
else
{
ySpeed += Physics.gravity.y * Time.deltaTime;
}
characterController.Move(velocity * Time.deltaTime);
if (moveAmount > 0)
{
targetRotation = Quaternion.LookRotation(moveDir);
}
transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, rotationSpeed * Time.deltaTime);
animator.SetFloat("moveAmount", moveAmount, 0.5f, Time.deltaTime);
}
void GroundCheck()
{
isGrounded = Physics.CheckSphere(transform.TransformPoint(groundCheckOffset), groundCheckRadius, groundLayer);
}
private void OnDrawGizmosSelected()
{
Gizmos.color = new Color(0, 0, 1, 0.5f);
Gizmos.DrawSphere(transform.TransformPoint(groundCheckOffset), groundCheckRadius);
}
IEnumerable DoJumpAnimation ()
{
inAction = true;
animator.CrossFade("Jump", 0.2f);
yield return null;
var animState = animator.GetNextAnimatorStateInfo(0);
yield return new WaitForSeconds(animState.length);
inAction = false;
}
}
And heres the error in unity
Assets\Scripts\Controllers\PlayerController.cs(50,28): error CS1503: Argument 1: cannot convert from ‘System.Collections.IEnumerable’ to ‘string’
This is a 3d Character Movement script if that means anything. Trying to make a jump function with animation. So far jump works, but animation doesnt.