I need help with a raycast script for jumping. I am very new to C#, and below I have the script I have for jumping and movement currently:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
private float Jumpheight = 5f;
private Rigidbody player;
private bool canJump;
public BoxCollider m_Collider;
// Start is called before the first frame update
void Start()
{
player = GetComponent<Rigidbody>();
Cursor.lockState = CursorLockMode.Locked;
//m_Collider = gameObject.GetComponent<BoxCollider>();
}
void FixedUpdate()
{
if (canJump)
{
canJump = false;
player.AddForce(0, Jumpheight, 0, ForceMode.Impulse);
}
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.W))
{
transform.Translate(Vector3.forward * Time.deltaTime * 5);
}
else if (Input.GetKey(KeyCode.S))
{
transform.Translate(Vector3.back * Time.deltaTime * 5);
}
else if (Input.GetKey(KeyCode.A))
{
transform.Translate(Vector3.left * Time.deltaTime * 5);
}
else if (Input.GetKey(KeyCode.D))
{
transform.Translate(Vector3.right * Time.deltaTime * 5);
}
if (Input.GetKeyUp(KeyCode.Space))
{
canJump = true;
}
if (Input.GetMouseButtonDown(0))
{
print("The Left mouse button was clicked");
}
else if (Input.GetMouseButtonDown(1))
{
print("The Right mouse button was clicked");
}
else if (Input.GetMouseButtonDown(2))
{
print("The Middle mouse button was clicked");
}
}
}
Any help here would be greatly appreciated!