I have been working on this wall running script and I cant seem to figure out why it only works the first time. I want it so the player can go from wall to wall and not have to touch ground.
note that the send message changes the players gravity to zero from anther script.
at the bottom it the url to the youtube video I followed.
Any ideas??
using System.Collections;
using System.Collections.Generic;
using System.Security.Cryptography;
using UnityEngine;
public class WallRun2 : MonoBehaviour
{
private bool isWallR = false;
private bool isWallL = false;
private RaycastHit hitR;
private RaycastHit hitL;
public int jumpCount = 0;
public Transform GroundCheck;
public float GroundDistance = 0.4f;
public LayerMask GroundMask;
bool Grounded;
private GameObject Player;
void Awake()
{
Player = GameObject.Find(“Player”);
}
void Update()
{
Grounded = Physics.CheckSphere(GroundCheck.position, GroundDistance, GroundMask);
if (Grounded)
{
jumpCount = 0;
}
if(Input.GetButton(“Jump”) && !Grounded /&& jumpCount <= 1/)
{
if(Physics.Raycast(transform.position, -transform.right, out hitL, 1))
{
if (hitL.transform.tag == “Wall”)
{
//isWallL = true;
//isWallR = false;
//jumpCount += 1;
Player.SendMessage(“WallRun”);
StartCoroutine(afterRun());
}
}
if (Physics.Raycast(transform.position, transform.right, out hitR, 1))
{
if (hitR.transform.tag == “Wall”)
{
//isWallL = false;
//isWallR = true;
//jumpCount += 1;
Player.SendMessage(“WallRun”);
StartCoroutine(afterRun());
}
}
}
IEnumerator afterRun ()
{
yield return new WaitForSeconds(0.5f);
//isWallL = false;
//isWallR = false;
Player.SendMessage(“NoWallRun”);
jumpCount = 0;
}
}
}
//