When the player collides with a object there is supposed to be a delay for three seconds then he jumps. But I have a problem, every time the player collides with a object jump is turned off. How do I get a delay jump when the player collides with a object?’
Also when the player collides with a object auto run is supposed turn off as well. How do I that?
Edit: I also very new to scripting
using UnityEngine;
using System.Collections;
public class MoveForward : MonoBehaviour {
public float speed = 6.0F;
public float delayJumpTime = 2.0f;
public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
private Vector3 moveDirection = Vector3.zero;
private bool autorun = true;
public bool delayjump= false;
void OnControllerColliderHit(ControllerColliderHit hit)
{
if (hit.collider.tag != "Jumpstuff")
{
Debug.Log("I'm Here");
delayjump = true;
}
//Invoke("changeAutoJump", 3);
}
public void Start ()
{
CharacterController c = GetComponent<CharacterController>();
c.detectCollisions = true;
}
// Update is called once per frame
void Update () {
CharacterController controller = GetComponent<CharacterController>();
if (controller.isGrounded) {
moveDirection = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 2);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton("Jump") delayjump == false)
{
moveDirection.y = jumpSpeed;
}
if (Input.GetButton("Jump") delayjump == true)
{
Pizza();
}
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
void changeAutoRun()
{
autorun = true;
}
void changeDelayJump()
{
delayjump = true;
}
IEnumerator Pizza()
{
yield return new WaitForSeconds(3.0f);
Debug.Log("We need to hurry");
moveDirection.y = jumpSpeed;
}
}