Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Haugkall · Mar 10, 2018 at 10:39 PM · bugsoundjumping

A tiny sound bug I'm not sure how to solve.

The character jumps, he hits the ground and a sound is played. It works but if you are about to fall and for that brief moment when the character is hitting the ground and the sound is played if you jump right at that moment the variables which enables the sound to play will be true a second time which makes the sound play twice. I tried disabling the jump for 0.1 seconds after you land but still if you hop around long enough the bug comes back. Any ideas on how to fix this? (Ignore the stomp)

 //Player jumping
         if (JumpingEnabled)
         {
             if (Input.GetButtonDown("Jump") && touchesGround)
             {
                 Jump.Play();
                 playerRigidBody.AddForce(0f, 325f, 0f);
                 secondJump = true;
             }
             else if (Input.GetButtonDown("Jump") && secondJump == true)
             {
                 StartCoroutine("Stomp");
             }
 
             else if (secondJump == true && touchesGround)
             {
                 secondJump = false;
                 ComesToGround.Play();
                 StartCoroutine("DisableJump");
             }
 
             else
             {
 
             }
         }
 
     IEnumerator DisableJump()
     {
         JumpingEnabled = false;
         yield return new WaitForSeconds(0.1f);
         JumpingEnabled = true;
     }
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
Best Answer

Answer by Haugkall · Mar 11, 2018 at 03:25 PM

I figured it out, had to not associate the sound with the jump.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class Character : MonoBehaviour
 {
 
     //Todo
     //•How to multiply rotation by deltaTime?
     //•Why can't I give the jump a float?
 
     Transform playerTransform;
     Rigidbody playerRigidBody;
 
     public AudioSource Jump;
     public AudioSource Stomping;
     public AudioSource AboutToStomp;
     public AudioSource ComesToGround;
 
     public AudioSource Tail1;
     public AudioSource Tail2;
     public AudioSource Tail3;
 
     public GameObject Stomper;
     public GameObject TailAttack;
     GameObject Ground;
 
     float characterFSpeed = 4.5f;
     float characterBSpeed = 1.75f;
     public bool touchesGround;
     public bool secondJump = true;
     public bool playerMovementEnabled = true;
     public bool stompingSoundPlayer = false;
     public bool JumpingEnabled = true;
     public bool tailAttacking = true;
     public bool fallsoundactivated;
 
     void Start()
     {
 
         playerTransform = GetComponent<Transform>();
         playerRigidBody = GetComponent<Rigidbody>();
         playerRigidBody.freezeRotation = true;
     }
 
     void Update()
     {
         if (tailAttacking == true)
         {
             if (Input.GetButtonDown("Fire3"))
             {
                 StartCoroutine("TailAttacking");
             }
         }
 
         //Is player movement enabled?
         if (playerMovementEnabled == true)
         {
             //Player rotation.
             playerTransform.Rotate(0, Input.GetAxis("Horizontal"), 0);
 
             //Player movement.
             float vertical = Input.GetAxis("Vertical");
 
             if (vertical > 0)
             {
                 vertical = characterFSpeed;
             }
 
             if (vertical < 0)
             {
                 vertical = -characterBSpeed;
             }
 
             playerTransform.Translate(0, 0, vertical * Time.deltaTime);
 
         }
 
         //Player jumping
         if (JumpingEnabled)
         {
             if (Input.GetButtonDown("Jump") && touchesGround)
             {
                 Jump.Play();
                 playerRigidBody.AddForce(0f, 325f, 0f);
                 secondJump = true;
             }
             else if (Input.GetButtonDown("Jump") && secondJump == true)
             {
                 StartCoroutine("Stomp");
             }
 
             else if (secondJump == true && touchesGround)
             {
                 JumpingEnabled = false;
                 secondJump = false;
                 StartCoroutine("DisableJump");
             }
 
             else
             {
 
             }
         }
 
         if (touchesGround == false)
         {
             fallsoundactivated = true;
         }
 
         if (touchesGround && fallsoundactivated == true)
         {
             Debug.Log("Detected");
             ComesToGround.Play();
             fallsoundactivated = false;
         }
 
         //When the character hits the ground after having stomped a sound is played.
         if (stompingSoundPlayer == true && touchesGround)
         {
             JumpingEnabled = false;
             Stomping.Play();
             stompingSoundPlayer = false;
             StartCoroutine("Stompdelay");
         }
 
     }
 
     IEnumerator TailAttacking()
     {
         tailAttacking = false;
         TailAttack.SetActive(true);
         //Add two more tail sounds here later when you know how.
         Tail1.Play();
         yield return new WaitForSeconds(0.3f);
         TailAttack.SetActive(false);
         yield return new WaitForSeconds(0.5f);
         tailAttacking = true;
     }
 
     //Disables for 0.1 seconds.
     IEnumerator DisableJump()
     {
         yield return new WaitForSeconds(0.1f);
         JumpingEnabled = true;
         yield return new WaitForSeconds(1f);
     }
 
     //A delay before the character is able to jump again.
     IEnumerator Stompdelay()
     {
         yield return new WaitForSeconds(0.5f);
         Stomper.SetActive(false);
         playerMovementEnabled = true;
         JumpingEnabled = true;
     }
 
     //The character freezes in the air and stomps towards the ground.
     IEnumerator Stomp()
     {
         JumpingEnabled = false;
         Stomper.SetActive(true);
         playerMovementEnabled = false;
         playerRigidBody.isKinematic = true;
         AboutToStomp.Play();
         yield return new WaitForSeconds(0.75f);
         playerRigidBody.isKinematic = false;
         stompingSoundPlayer = true;
         secondJump = false;
         playerRigidBody.AddForce(0f, -1500f, 0f);
     }
 
     void OnCollisionEnter(Collision Ground)
     {
         if (Ground.gameObject.tag == "Ground")
         {
             touchesGround = true;
             fallsoundactivated = true;
         }
     }
 
     void OnCollisionExit(Collision Ground)
     {
         if (Ground.gameObject.tag == "Ground")
         {
             touchesGround = false;
         }
     }
 }
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

135 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

Related Questions

My Unity Makes USB Attached Sound 0 Answers

While (starting jumping or in jump) holding W key makes game object jump high and fall slow. 1 Answer

Attaching sound to ImageTarget issues 0 Answers

Sound bug - Emergency HELP 0 Answers

No sound after recieving a phone call - Android 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