The body of MouseMovement.Delay()' cannot be an iterator block because
void’ is not an iterator interface type
What does this mean? I’ve been converting JS to C# scripts… and I’m not getting this part, can you pleas help?
using UnityEngine;
using System.Collections;
public class MouseMovement : MonoBehaviour
{
private float jumpSpeed = 18.0f;
private float gravity = 32.0f;
private float runSpeed = 15.0f;
private float walkSpeed = 45.0f;
private float rotateSpeed = 150.0f;
private bool grounded = false;
private Vector3 moveDirection = Vector3.zero;
private bool isWalking = false;
private string moveStatus = "idle";
GameObject trigger;
static bool dead = false;
private int attack;
Transform attackPosition;
void Start()
{
}
void Delay()
{
yield return new WaitForSeconds(5);
}
void Update()
{
if (dead == false)
{
if (Input.GetKeyDown("f"))
{
attack = true;
moveStatus = "attack";
animation.Play("punch", PlayMode.StopAll);
//animation.Play("upperjab", PlayMode.StopAll);
delay();
// Instantiate(trigger, attackPosition.position, attackPosition.rotation);
}
// Only allow movement and jumps while grounded
if (grounded)
{
if (Input.GetKey(KeyCode.A) && (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.S)))
{
animation.CrossFade("strafeLeft", 0.2f);
//animation.Play("strafeLeft", PlayMode.StopAll);
}
if (Input.GetKey(KeyCode.D) && (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.S)))
{
animation.CrossFade("strafeRight", 0.2f);
//animation.Play("strafeRight", PlayMode.StopAll);
}
if (moveStatus == "idle")
{
animation.Play("idle");
}
moveDirection = new Vector3((Input.GetMouseButton(1) ? Input.GetAxis("Horizontal") : 0), 0, Input.GetAxis("Vertical"));
// if moving forward and to the side at the same time, compensate for distance
// TODO: may be better way to do this?
if (Input.GetMouseButton("1") && Input.GetAxis("Horizontal") && Input.GetAxis("Vertical"))
{
moveDirection *= 7;
}
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= isWalking ? walkSpeed : runSpeed;
moveStatus = "idle";
if (moveDirection != Vector3.zero)
{
moveStatus = isWalking ? "walking" : "running";
}
if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.S))
{
animation.CrossFade("run", 0.2f);
}
// Jump!
//if(Input.GetButton("Jump"))
if (Input.GetKeyDown(KeyCode.Space))
{
animation.Play("jump", PlayMode.StopAll);
moveDirection.y = jumpSpeed;
}
}
// Allow turning at anytime. Keep the character facing in the same direction as the Camera if the right mouse button is down.
if (Input.GetMouseButton(1))
{
transform.rotation = Quaternion.Euler(0, Camera.main.transform.eulerAngles.y, 0);
}
else
{
transform.Rotate(0, Input.GetAxis("Horizontal") * rotateSpeed * Time.deltaTime, 0);
}
// Toggle walking/running with the T key
//if(Input.GetKeyDown("t"))
//isWalking = !isWalking;
//Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
//Move controller
CharacterController controller = GetComponent<CharacterController>();
bool flags = controller.Move(moveDirection * Time.deltaTime);
grounded = (flags & CollisionFlags.Below) != 0;
}
if (Input.GetMouseButton(1) || Input.GetMouseButton(0))
{
//Screen.lockCursor = true;
//Screen.showCursor = false;
//void mouse1= Input.mousePosition.y;
//void mouse2= Input.mousePosition.x;
}
//Vector3 mousePos = Input.mousePosition;
else
{
//Screen.lockCursor = false;
//Screen.showCursor = false;
//Input.mousePosition.y = mouse1;
//Input.mousePosition.x = mouse2;
//Input.mousePosition = mousePos;
}
}
//@script RequireComponent(CharacterController);
}