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 Lefti97 · Jan 21, 2014 at 06:01 PM · errorbeginnernoob

Disable function OnTriggerExit?

Hi i am a complete beginner at programming. I made a sphere that can jump and move horizontally.

public class PlayerControler1 : MonoBehaviour {

     public float speed;
     public float JumpSpeed;
     
     void FixedUpdate ()
     {
         movement ();
     }
 
     void movement ()
     {
         float h = Input.GetAxis ("Horizontal") * speed;
         rigidbody.AddForce (h, 0f, 0f);
 
         Jump ();
     }
     public void Jump ()
     {
         if (Input.GetButtonDown ("Jump"))
             rigidbody.AddForce (0f, JumpSpeed, 0f);
     }


Now the problem is i want to make it jump only when its grounded so i made a child empty gameobject inside my sphere and added a sphere collider in it and made it trigger, i made it a little bigger than the player sphere collider.

I made a script in it and did the inheritance thing. Now i want it to disable the Jump function when the trigger collider exits the ground.

So i made this

 public class JumpDead : PlayerControler1 {
     
     void OnTriggerExit (Collider Ground)
     {
         Jump (false);
     }

But when i return to play the game it gives me an error.
Assets/JumpDead.cs(8,17): error CS1501: No overload for method Jump' takes 1' arguments.

Can someone explain me what im doing wrong and how to do it right ?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Ferb · Jan 21, 2014 at 06:50 PM

The line:

 Jump(false);

is trying to send the argument 'false' to your 'Jump' function, which as it says, doesn't take any arguments (the brackets after 'Jump' are empty).

A better idea would be to have a variable - maybe called 'canJump', and just check that when you want to jump. So add a line at the top saying:

 private bool canJump = true;

(bool means it's a type of variable that is either true or false) and make your Jump code:

 if (Input.GetButtonDown ("Jump"))
 if(canJump)
 rigidbody.AddForce (0f, JumpSpeed, 0f);

Now your collider doesn't need to call any function, it just needs to set 'canJump' to either true or false. I'd recommend you just make those changes to your original PlayerControler class for now though, I don't see any reason you need to inherit a new class, that's just complicating things. And if you set canJump to false in OnTriggerExit, remember to set it to true again in OnTriggerEnter. If you have more trouble, try watching the tutorial here, which covers the subject of jumping in a 2D game. http://unity3d.com/learn/tutorials/modules/beginner/2d/2d-controllers

Comment
Add comment · Show 1 · 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
avatar image Lefti97 · Jan 21, 2014 at 07:03 PM 0
Share

i dont know what im doing wrong it still jumps while on air

avatar image
0

Answer by skalev · Jan 21, 2014 at 06:37 PM

Calling Jump(false) doesn't disable your function. It calls it with false as a parameter.

Since you have no function that is called Jump and takes one parameter of type bool, it cannot compile.

what you want is to have a bool flag that is checked.

so under JumpSpeed you add:

 public bool canJump = true;

in the jump function you change the condition to:

 if (Input.GetButtonDown ("Jump") && canJump)

And finally in OnTriggerExit(), you change the call to be:

 canJump = false;

As a note this is really not the best solution what so ever, but this is what needs to change to make it work.

Comment
Add comment · Show 1 · 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
avatar image Lefti97 · Jan 21, 2014 at 06:49 PM 0
Share

it still jumps while on air

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

19 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

Related Questions

BEGINNER: why is my main menu not loading level 1 when I press play? 1 Answer

Greater than and less than syntax problem 1 Answer

X is a variable but a type was expected 1 Answer

Help With "Scripting" 1 Answer

Having trouble with wheel colliders. (IMMA NEWB) 0 Answers


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