In Unity 5, I am trying to create a simple character controller for a cube. I have a plane parented to the bottom of the cube to check for collisions with the ground to reset a “grounded” bool variable. The compiler says:
CollisionChecker.cs(11, 45) Keyword ‘void’ cannot be used in this context
CollisionChecker.cs(11, 46) Unexpected symbol ‘(’
CollisionChecker.cs(16, 1) Parsing error
Here are the 2 pieces of code I have, one directly on the cube and the other on the parented plane.
Cube’s Code:
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
public Rigidbody player;
public float moveBackwardMultiplier = 1;
public float moveForwardMultiplier = 1;
public float moveSidewaysMultiplier = 1;
public float jumpForce;
public float jumpMultiplier = 1;
public bool grounded = true;
void Jump () {
while(grounded){
if(Input.GetButtonDown("Jump")){
grounded = false;
Vector3 vectorJump = new Vector3 (0, jumpForce, 0);
player.AddForce(vectorJump * jumpMultiplier);
}
}
}
void Start() {
player = gameObject.GetComponent<Rigidbody> ();
}
}
Plane’s Code:
using UnityEngine;
using System.Collections;
public class CollisionChecker : MonoBehaviour {
public PlayerController playerController;
void Start() {
playerController = gameObject.GetComponentInParent<PlayerController> ();
}
void FixedUpdate() {
while(!playerController.grounded){
void OnCollisionEnter(Collider other){
playerController.grounded = true;
}
}
}
}
If anyone could help me out with why my code is not working I would really appreciate it or even more so if they told me a better way of doing it than the way I am now.