Coroutines and Yield

I’m working on a script where I’m trying to implement a yield. The script is for jumping. I having having trouble getting the player to delay jumping once they collide with with a wall. Here is what I have so far:

using UnityEngine;
using System.Collections;

public class Jumpscript : MonoBehaviour {

IENumerator(DelayedJump){

while (true){
yield return new WaitForSeconds(5.0f);
OnCollisionEnter(Collision collisionInfo)){
if (Gameobject.collisionInfo.tag == (“Yourtag”) {
}}

DelayedJump();

}}
public float speed = 10.0f;
public float jumpForce = 10.0f;
public float airModifier = 0.2f;

public void Update()
{
bool grounded;

//is the user pressing left or right (or "a “d”) on the keyboard?
Vector3 horMovement = Input.GetAxis(“Horizontal”) * transform.right * Time.deltaTime * speed;
//is the user pressing up or down (or “w” “s”) on the keyboard?
Vector3 forwardMovement = Input.GetAxis(“Vertical”) * transform.forward * Time.deltaTime * speed;

//are we grounded?
if (Physics.Raycast(transform.position, -transform.up, 2)) {
grounded = true;
} else {
horMovement *= airModifier;
forwardMovement *= airModifier;
grounded = false;
}

//jump if the user pressing the space key AND our character is grounded
if (Input.GetKeyUp(“space”) grounded)
{
rigidbody.AddRelativeForce(transform.up * jumpForce, ForceMode.Impulse);

}

//move our character
transform.Translate(forwardMovement + horMovement);

}

}

I have been referencing from here without any luck: http://docs.unity3d.com/Documentation/ScriptReference/index.Coroutines_26_Yield.html

How do I solve this?Thanks!

Welcome to the forum!

Sorry to tell you that, but this script makes no sense. I have the impression that you don’t know how to use C# properly and should first learn the basics.

PS It is a lot easier to read code, if you use code tags.

I am familiar with C# and have gone through basics.I do agree that the script makes no sense. This is the code I am trying to insert into my script to have the player delay jumping when they collide with an object:

IENumerator(DelayedJump){

yield return new WaitForSeconds(Youramountofseconds here);

(Insert code of jumping here)

}

OnCollisionEnter(Collision collisionInfo){

if (Gameobject.collisionInfo.tag == ("Yourtag") {

DelayedJump();

}

I’m trying to get that code wrapped around my jump code. Any ideas? Thanks.

IEnumerator is only the return type. You still need a method name! And this method has to be started. You find that information at the end of the documentation page you have linked. On the StartCoroutine documentation page you find this very simple example. I am sure this will help you to get a better understanding.

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
    void Start() {
        print("Starting " + Time.time);
        StartCoroutine(WaitAndPrint(2.0F));
        print("Before WaitAndPrint Finishes " + Time.time);
    }
    IEnumerator WaitAndPrint(float waitTime) {
        yield return new WaitForSeconds(waitTime);
        print("WaitAndPrint " + Time.time);
    }
}

Thanks!