HI, I'm new to unity, I'm following an fps tutorial and get this error. Here is my code. `using System.Collections;
using System.Collections.Generic;
using System.Security.Cryptography;
using UnityEngine;
public class PlayerMove : MonoBehaviour
{
float moveForward;
float moveSide;
float moveUp;
public float speed = 5f;
public float jumpSpeed = 10f;
Rigidbody rig;
bool isGrounded;
// Start is called before the first frame update
void Start()
{
rig = GetComponent();
}
// Update is called once per frame
void Update()
{
moveForward = Input.GetAxis("Vertical") * speed;
moveSide = Input.GetAxis("Horizontal") * speed;
moveUp = Input.GetAxis("Jump") * jumpSpeed;
rig.velocity = (transform.forward * moveForward) + (transform.right * moveSide) + (transform.up * rig.velocity.y);
if(isGrounded && moveUp != 0)
{
rig.AddForce(transform.up = moveUp, ForceMode.VelocityChange);
isGrounded = false;
}
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Gtound")
isGrounded = true;
}
private void OnCollisionExit(Collision collision)
{
if (collision.gameObject.tag == "Gtound")
isGrounded = false;
}
}
`
↧