Hello i’m trying to apply a script into kart microgame but it not having any effects, when assigned to gameobject everything seems fine but nothing happening in the game as I want the object to jump everytime the spacebar button is pressed, so i’m thinking maybe I assigned my script to the wrong object or maybe the script is just not complete for what i want to achieve. Could you take a look at my code tell me if it fine and if so why do you think it not working in game, any help will be much appriciated.
Here’s the code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class JumpScript : MonoBehaviour
{
// Start is called before the first frame update
public Vector3 jump;
public float jumpForce = 2.0f;
public bool isGrounded;
Rigidbody rb;
void Start(){
rb = GetComponent<Rigidbody>();
jump = new Vector3(0.0f, 2.0f, 0.0f);
}
void OnCollisionStay(){
isGrounded = true;
}
void Update(){
if(Input.GetKeyDown(KeyCode.Space) && isGrounded){
rb.AddForce(jump * jumpForce, ForceMode.Impulse);
isGrounded = false;
}
}
}
Script assigned to KartClassic_Player