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!