So I've just started coding, and obviously I did some things wrong.
I wanted to make a jump script in which jumpDelay turns FALSE when the button is pressed, and TRUE when the player hits the ground.
The problem is that "Cannot implicitly convert type 'bool' to 'PlayerCollision'. "
I do not know what I did wrong, so I appriciate help.
Thanks!
I wanted to make a jump script in which jumpDelay turns FALSE when the button is pressed, and TRUE when the player hits the ground.
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public Rigidbody rb;
public float forwardForce = 800f;
public float sidewaysForce = 500f;
public PlayerCollision jumpDelay;
// Update is called once per frame
void FixedUpdate()
{
//movement to right
if (Input.GetKey("d"))
{
rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
//movement to left
if (Input.GetKey("a"))
{
rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
//movement to forward
if (Input.GetKey("w"))
{
rb.AddForce(0, 0, forwardForce * Time.deltaTime);
}
//movement to backward
if (Input.GetKey("s"))
{
rb.AddForce(0 , 0 , -forwardForce * Time.deltaTime);
}
if (Input.GetKeyUp("space")&&jumpDelay==true)
{
rb.AddForce(0, 50, 0, ForceMode.Force);
jumpDelay=false;
}
if(rb.position.y<-1)
{
FindObjectOfType<GameManager>().EndGame();
}
}
public class PlayerMovement : MonoBehaviour
{
public Rigidbody rb;
public float forwardForce = 800f;
public float sidewaysForce = 500f;
public PlayerCollision jumpDelay;
// Update is called once per frame
void FixedUpdate()
{
//movement to right
if (Input.GetKey("d"))
{
rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
//movement to left
if (Input.GetKey("a"))
{
rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
//movement to forward
if (Input.GetKey("w"))
{
rb.AddForce(0, 0, forwardForce * Time.deltaTime);
}
//movement to backward
if (Input.GetKey("s"))
{
rb.AddForce(0 , 0 , -forwardForce * Time.deltaTime);
}
if (Input.GetKeyUp("space")&&jumpDelay==true)
{
rb.AddForce(0, 50, 0, ForceMode.Force);
jumpDelay=false;
}
if(rb.position.y<-1)
{
FindObjectOfType<GameManager>().EndGame();
}
}
using UnityEngine;
public class PlayerCollision : MonoBehaviour
{
public PlayerMovement movement;
public bool jumpDelay = false;
void OnCollisionEnter (Collision collisionInfo)
{
if (collisionInfo.collider.tag == "Obstacle")
{
movement.enabled = false;
FindObjectOfType<GameManager>().EndGame();
}
if (collisionInfo.collider.name=="Ground")
{
jumpDelay=true;
}
}
}
public class PlayerCollision : MonoBehaviour
{
public PlayerMovement movement;
public bool jumpDelay = false;
void OnCollisionEnter (Collision collisionInfo)
{
if (collisionInfo.collider.tag == "Obstacle")
{
movement.enabled = false;
FindObjectOfType<GameManager>().EndGame();
}
if (collisionInfo.collider.name=="Ground")
{
jumpDelay=true;
}
}
}
The problem is that "Cannot implicitly convert type 'bool' to 'PlayerCollision'. "
I do not know what I did wrong, so I appriciate help.
Thanks!