Jump to content

While using Input.GetButtonDown , Unity does not have a compiling issue but it pauses the game in play mode. Here is the code.

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class playerjump : MonoBehaviour
{
    public Rigidbody2D rb;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        

        if (Input.GetButtonDown("mouse")) ;
        {
            rb.velocity = new Vector2(rb.velocity.x, 5);
        }
    }
}

I cannot paste this code into my move forward code for some reason, unity just doesn't like this. 

 

I'm sure I'm doing something wrong. Maybe someone can help?

 

All help is appreciated,

 

Thanks!

Link to comment
https://linustechtips.com/topic/1027381-unity-getbuttondown-issue/
Share on other sites

Link to post
Share on other sites

I believe there are values in the inspector when you click the cube, mind screenshotting the inspector for me?

 

I use unity and made a similar script (I don’t remember how though) but I had to mess around in the inspector

✧・゚: *✧・゚:*  Quote for a reply  *:・゚✧*:・゚✧

 

✧・゚: *✧・゚:*   Ask for discord   *:・゚✧*:・゚✧

Link to post
Share on other sites

2 minutes ago, iLostMyXbox21 said:

I believe there are values in the inspector when you click the cube, mind screenshotting the inspector for me?

 

I use unity and made a similar script (I don’t remember how though) but I had to mess around in the inspector

This is when play button isn't clicked.

image.png.367e47db5759e81f53a59160ac510e28.png

 

This is play button clicked but it enabled the pause button.

 

image.png.3aba55ea3b60eeda043f6d5f5f246212.png

 

I'm guessing i need the playerjump which is the attached code in the first post to say bird (its to make a bird move)

 

thanks for your reply!

Link to post
Share on other sites

1 minute ago, EoinP said:

This is when play button isn't clicked.

image.png.367e47db5759e81f53a59160ac510e28.png

 

This is play button clicked but it enabled the pause button.

 

image.png.3aba55ea3b60eeda043f6d5f5f246212.png

 

I'm guessing i need the playerjump which is the attached code in the first post to say bird (its to make a bird move)

 

thanks for your reply!

I think under “Playerjump” you have to have the “bird (Rigidbody 2D)” in it where it says “none (Rigidbody 2D)”

 

And no problem

✧・゚: *✧・゚:*  Quote for a reply  *:・゚✧*:・゚✧

 

✧・゚: *✧・゚:*   Ask for discord   *:・゚✧*:・゚✧

Link to post
Share on other sites

Just now, iLostMyXbox21 said:

I think under “Playerjump” you have to have the “bird (Rigidbody 2D)” in it where it says “none (Rigidbody 2D)”

 

And no problem

there is no drop down to change it. Both have no dropdowns. only when play is clicked does playercontrols have bird rigidbody.

 

on play no drop down appears either.

Link to post
Share on other sites

Just now, EoinP said:

there is no drop down to change it. Both have no dropdowns. only when play is clicked does playercontrols have bird rigidbody.

 

on play no drop down appears either.

There isn’t a drop down, you have to go to the hierarchy or content library and drag and drop it into the bar

✧・゚: *✧・゚:*  Quote for a reply  *:・゚✧*:・゚✧

 

✧・゚: *✧・゚:*   Ask for discord   *:・゚✧*:・゚✧

Link to post
Share on other sites

6 minutes ago, iLostMyXbox21 said:

There isn’t a drop down, you have to go to the hierarchy or content library and drag and drop it into the bar

Would this be of any help maybe.

 

image.png.d6646a16b14038500b33af07ec7b06ab.png

 

got this in console when i tried to use the fast forward button.

 

thanks

Link to post
Share on other sites

3 minutes ago, EoinP said:

Would this be of any help maybe.

 

image.png.d6646a16b14038500b33af07ec7b06ab.png

 

got this in console when i tried to use the fast forward button.

 

thanks

Did you drag in the bird rigid body into the playerjump part?

 

basically it’s saying “you said there is something here, but you’re not telling me what” meaning you called the Rigidbody (“public Rigidbody2D rb; “) but you didn’t fill out what it is in the inspector, so when unity tries to apply it, it can’t because you didn’t tell it what rb is.

 

i believe so, it’s been a while since I’ve used unity (about 2 months)

✧・゚: *✧・゚:*  Quote for a reply  *:・゚✧*:・゚✧

 

✧・゚: *✧・゚:*   Ask for discord   *:・゚✧*:・゚✧

Link to post
Share on other sites

2 minutes ago, iLostMyXbox21 said:

Did you drag in the bird rigid body into the playerjump part?

 

basically it’s saying “you said there is something here, but you’re not telling me what” meaning you called the Rigidbody (“public Rigidbody2D rb; “) but you didn’t fill out what it is in the inspector, so when unity tries to apply it, it can’t because you didn’t tell it what rb is.

 

i believe so, it’s been a while since I’ve used unity (about 2 months)

hi I applied it after I sent u that last reply and it works, until u stop the game altogether and restart it then it disappears again. And then proceeds with the same error. Is there some code i can write to apply the rb?

 

Many thanks

Link to post
Share on other sites

4 minutes ago, iLostMyXbox21 said:

Did you drag in the bird rigid body into the playerjump part?

 

basically it’s saying “you said there is something here, but you’re not telling me what” meaning you called the Rigidbody (“public Rigidbody2D rb; “) but you didn’t fill out what it is in the inspector, so when unity tries to apply it, it can’t because you didn’t tell it what rb is.

 

i believe so, it’s been a while since I’ve used unity (about 2 months)

Okay, I found the issue,

 

I added

 

    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
    }

 and now it auto adds it. I appreciate your help I wouldn't have understood this without it!

 

Many thanks again

Link to post
Share on other sites

Just now, EoinP said:

hi I applied it after I sent u that last reply and it works, until u stop the game altogether and restart it then it disappears again. And then proceeds with the same error. Is there some code i can write to apply the rb?

 

Many thanks

You can’t apply it while the game is playing, you have to stop it, apply, and then replay the game. Reason being is the game viewer needs time to recompile the code, check for errors, etc. so try stopping it and then dragging it in. Then press play and it should work

 

i had that same issue once, I worked on it for 30 minutes, got a ton of work done, and then stopped the simulation and it removed everything

✧・゚: *✧・゚:*  Quote for a reply  *:・゚✧*:・゚✧

 

✧・゚: *✧・゚:*   Ask for discord   *:・゚✧*:・゚✧

Link to post
Share on other sites

Just now, EoinP said:

Okay, I found the issue,

 

I added

 


    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
    }

 and now it auto adds it. I appreciate your help I wouldn't have understood this without it!

 

Many thanks again

Oh yeah that’s one way to do it, personally I prefer doing it in the inspector but that’s just because I prefer shorter scripts

 

and no problem

✧・゚: *✧・゚:*  Quote for a reply  *:・゚✧*:・゚✧

 

✧・゚: *✧・゚:*   Ask for discord   *:・゚✧*:・゚✧

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×