Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by ahlamhamid123 · Jul 18, 2020 at 10:11 PM · dash

How to limit the amount of dashes in Unity 2020.2.0a15.1993?

Hello all! I am making a 2D top down shooter and I have a player that can move around the map, which is randomly generated. My player can dash around the map, but I want a limit for the amount of dashes in each level, for example: 3. How do I do it? Here's my code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 public class Player : MonoBehaviour
 {
     //Dash
     private bool isDashing;
     public float dashDistance;
 
     private void Awake()
     {
         rb = GetComponent<Rigidbody2D>();
     }
 
     private void Update()
     {
         //Dash
         if (Input.GetMouseButtonDown(1))
         {
             isDashing = true;
         }
     }
 
     private void FixedUpdate()
     {
         //Dash
         if (isDashing)
         {
             rb.MovePosition(transform.position + (moveDirection * dashDistance));
             isDashing = false;
         }
     }
 }   

All help will be appreciated. Thanks, Ahlam Hamid

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 CC_1759 · Aug 27, 2021 at 07:45 PM

@ahlamhamid123 put an int (ill call it timesDashed) and increment it when you dash. also put an if statement before GetMouseButtonDown which says if (timesDashed != 3). make a function that sets timesDashed to 0 and then in your script to go to another level refrence it. and if you want it to be able to set the amount of dashes they can do you can make another int (i called it dashLimit) this time public and replace the three in the if statement with it, and in the function for reseting timesDashed put one of these thing public void function(int whateverTheseAreCalledIDontRememer) and then set dashLimit to the paramiter in the function.

using System.Collections; using System.Collections.Generic; using UnityEngine; public class Player : MonoBehaviour { //Dash public float dashDistance; public int dashLimit; bool isDashing; int timesDashed; private void Awake() { rb = GetComponent<Rigidbody2D>(); } private void Update() { //Dash if (Input.GetMouseButtonDown(1)) { isDashing = true; } } private void FixedUpdate() { //Dash if (timesDashed != dashLimit) { if (isDashing) { rb.MovePosition(transform.position + (moveDirection * dashDistance)); isDashing = false; dashLimit += 1; } } } public ResetDashLimit(int setAmountOfDashes) { dashLimit = setAmountOfDashes; timesDashed = 0; } }

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 CC_1759 · Aug 27, 2021 at 07:50 PM 0
Share
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 public class Player : MonoBehaviour
 {
     //Dash
     public float dashDistance;
     public int dashLimit;
     bool isDashing;
     int timesDashed;
 
     private void Awake()
     {
         rb = GetComponent<Rigidbody2D>();
     }
 
     private void Update()
     {
         //Dash
         if (timesDashed != dashLimit)
         {
             if (Input.GetMouseButtonDown(1))
             {
                 isDashing = true;
             }
         }
     }
 
     private void FixedUpdate()
     {
         //Dash
         if (isDashing)
         {
             rb.MovePosition(transform.position + (moveDirection * dashDistance));
             isDashing = false;
         }
     }
 
     public void ResetDashLimit(int setAmountOfDashes) 
     { 
         dashLimit = setAmountOfDashes;
         timesDashed = 0;
     }
 }


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

204 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 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

Script works fine in Mac but won't work correctly on (my) PC 0 Answers

How to add dash to my character in Unity 3D? 0 Answers

Dashing cube ability problem 1 Answer

How to make a Flash Step effect? 0 Answers

Speed boost button for player 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