Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by nkress · Mar 02, 2021 at 09:12 AM · jumpjumpingjumping object

change multiple jump to single jump

I am doing the flappy bird project and now I am finished and I want to change the flying into a single jump. I have also watched at a video of a single jump example but it says: Assets\Script\Bird.cs(28,53): error CS0103: The name 'jumpVelocity' does not exist in the current context and: Assets\Script\Bird.cs(29,33): error CS0019: Operator '*' cannot be applied to operands of type 'Vector2' and 'void'

my script: using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Bird : MonoBehaviour {

 public float upForce = 200f;

 private bool isDead = false;
 private Rigidbody2D rb2d;
 private Animator anim;
 private Rigidbody2D rigidbody2d;
 // Start is called before the first frame update
 void Start()
 {
     rb2d = GetComponent<Rigidbody2D>();
     anim = GetComponent<Animator>();
 }

 // Update is called once per frame
 void Update()
 {
     if (isDead == false)
     {
         if (Input.GetMouseButtonDown(0))
         {
             rigidbody2d.velocity = Vector2.up * jumpVelocity;
             rb2d.velocity = Vector2.up * 
             rb2d.AddForce(new Vector2(0, upForce));
             anim.SetTrigger("Flap");
         }
     }
 }

 void OnCollisionEnter2D()
 {
     rb2d.velocity = Vector2.zero;
     isDead = true;
     anim.SetTrigger("Die");
     GameController.instance.BirdDied();
 }

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by pauldarius98 · Mar 02, 2021 at 10:07 AM

I guess you are new to programming so i want to tell you that the compiler is your friend and it will point out what you are doing wrong. When you have errors, you can search what that error means and usually you will see what you did wrong in your code. Now, let's take a look at the errors:


  1. 'jumpVelocity' does not exist in the current context means that we used a variable named jumpVelocity but we never declared it. This can be fixed very easy by declaring it at the top of our class (or anywhere but is good to declare the variables at the top of your classes) like this:

       public float upForce = 200f;
          private bool isDead = false;
          private Rigidbody2D rb2d;
          private Animator anim;
          private Rigidbody2D rigidbody2d;
         private float jumpVelocity = 300f; //Change 300 with whatever value you want
         ...
    
    
    

  2. Operator '' cannot be applied to operands of type 'Vector2' and 'void': It means that we tried to multiply a Vector2 with void (you see that you wrote nothing after the ?. From your context, i guess that you wanted to multiply it with the upForce like this:

      rb2d.velocity = Vector2.up * upForce;
    
    

Do this changes and see if your code compiles now

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

114 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

2d rigidbody jump not working 1 Answer

How can I limit jump height in unity? 3 Answers

I cant make my character jump 1 Answer

my jump key works about once every 10 presses 1 Answer

I need help with fixing my "up special" mechanic. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges