Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

claytr

New Coder
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.
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();
}





}

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;
}


}




}

The problem is that "Cannot implicitly convert type 'bool' to 'PlayerCollision'. "
I do not know what I did wrong, so I appriciate help.
Thanks!
 
Hey there.

If you want to get help here on CF, you're advised to post your source-code(We don't need every single source-file, just the file(s) that you're having trouble in). Without seeing your code, there is very little we can do to help.

Thanks.
 
Hey.

Good to hear that you've solved it. If you want to, you can post your updated code, with a comment next to the lines that you've changed. Doing this will help others who were originally experiencing the same issue as you, be able to see where to put the fix.

claytr said:
My source code is in the spoilers, is it not?
Yeah, it was. My apologies, I browse the web with JS disabled. I did enable it temporarily on mobile though and only then did I see the spoiler.
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom