I have followed an old unfinished tutorial to try and learn C# and I got the character controller working but when i jump my character controller infinitely jumping. i have tried multiple things but nothing has worked. i’m not asking for people to do it for me, i want an explanation on how to make it work properly.
thanks in advance.
here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMov : MonoBehaviour {
public Transform playertrn;
public Rigidbody playerRB;
public int speed;
private bool isFalling = false;
private bool doubleJump = false;
public Vector3 JumpHeight = new Vector3 (0, 8, 0);
void Start ()
{
playertrn = GetComponent<Transform> ();
playerRB = GetComponent<Rigidbody> ();
Physics.gravity = new Vector3(0, -15.0F, 0);
}
void Update ()
{
if (Input.GetKey (KeyCode.D))
{
playertrn.Translate (new Vector3(speed, 0, 0) * speed * Time.deltaTime);
}
if (Input.GetKey (KeyCode.A))
{
playertrn.Translate (new Vector3 (-speed, 0, 0) * speed * Time.deltaTime);
}
if (Input.GetKey (KeyCode.Space))
{
playerRB.velocity = JumpHeight;
isFalling = true;
}
}
void OnCollisionStay ()
{
isFalling = false;
}
}