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 /
This question was closed Jan 19, 2018 at 11:59 AM by dodpoo6 for the following reason:

no one helped so i guess i can only fix it on my own

avatar image
0
Question by dodpoo6 · Dec 22, 2017 at 12:54 PM · unity 5unity 2d

sound.Play() will not work

i am very new to coding so I'm not the greatest person to do. i found a bug with my game that my deathSong.Play() would not work (near the bottom). some reason all the other things in Die() work perfectly fine including the death menu its just the song wont play even though i have carried the Audio Source into the correct place and everything, its not muted or disabled, it just doesnt play. is there anyone that can tell me whats going on in my 2d game?

 public class Player_move : MonoBehaviour
 {
     public bool cantMove = false;
     public bool cutSceneActivated = false;
     public int playerHealth;
     public int playerSpeed = 1;
     public float moveX;
     public int jumpPower = 125;
     public bool isGrounded;
     private int maxHealth = 5;
     public DeathMenu deathMenu;
     private float startTime;
     public Score score;
     public bool hit = false;
     public AudioSource hurtSound;
     public AudioSource mainTheme;
     public AudioSource deathSong;
 
     public float knockBackAmount = 50;
 
 
     void Start()
     {
         playerHealth = maxHealth;
         //startTime = Time.time;
     }
 
     void Update ()
     {
 
         if (hit == true)
         {
             hurtSound.Play();
             hit = false;
         }
         else if (playerHealth <= 0)
         {
             Die();
         }
         else if (!cantMove)
         {
             playerMove();
 
             if (moveX > 0.0f && moveX != 1.0f)
             {
                 GetComponent<Animator>().SetBool("IsWalking", true);
             }
             else if (moveX < 0.0f && moveX != -1.0f)
             {
                 GetComponent<Animator>().SetBool("IsWalking", true);
             }
             else if (moveX == 1.0f)
             {
                 GetComponent<Animator>().SetBool("IsRunning", true);
             }
             else if (moveX == -1.0f)
             {
                 GetComponent<Animator>().SetBool("IsRunning", true);
             }
             else
             {
                 GetComponent<Animator>().SetBool("IsRunning", false);
                 GetComponent<Animator>().SetBool("IsWalking", false);
             }
         }
 
     }
     void jump()
     {
         GetComponent<Rigidbody2D>().AddForce(Vector2.up * jumpPower);
         isGrounded = false;
     }
 
     void OnTriggerEnter2D(Collider2D collision)
     {
         if (collision.gameObject.name == "DeathZone")
         {
             Die();
         }
     }
     public void cutScene()
     {
         if (cutSceneActivated)
         {
             cantMove = true;
         }
         else if(!cutSceneActivated)
         {
             cantMove = false;
         }
     }
     void playerMove()
     {
         moveX = Input.GetAxis("Horizontal");
         if (Input.GetButtonDown("Jump") && isGrounded)
         {
             jump();
         }
         if (moveX < 0.0f)
         {
             GetComponent<SpriteRenderer>().flipX = true;
         }
         else if (moveX > 0.0f)
         {
             GetComponent<SpriteRenderer>().flipX = false;
         }
         gameObject.GetComponent<Rigidbody2D>().velocity = new Vector2(moveX * playerSpeed, gameObject.GetComponent<Rigidbody2D>().velocity.y);
         
     }
        // fix this
     void Die()
     {
         mainTheme.enabled = false;
         hurtSound.enabled = false;
         //this next line of code needs to be fixed
         deathSong.Play();
         cantMove = true;
         moveX = 0;
         deathMenu.ToggleEndMenu();
     }
 }
 

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

  • Sort: 
avatar image
0

Answer by zero_null · Dec 22, 2017 at 02:47 PM

You need to make sure that the deathSong AudioSource have a Audio clip and the auto Play isn't checked. If there is no clip then you must assign the clip before you ask it to play. Which clip is assigned to the deathSong ?

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 dodpoo6 · Dec 22, 2017 at 10:57 PM 0
Share

this image shows the other 2 audio sources being disabled as i made it cause its annoying having hit noises and i game music playing when you play the game. however nothing has changed with the death song. its not unticked or muted in any way so it should play thanks for the help by the way :)alt text where as before play and after they dont change either thanks for the reply :)

audio-source-problem-on-death.png (106.6 kB)

Follow this Question

Answers Answers and Comments

145 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

Related Questions

InvokeRepeating time doesn't sync within the same update function 2 Answers

Unity Editor not installing from unity hub.,Unity Editor is not installing from unity hub. 0 Answers

How to create a hero's range of action? 0 Answers

How to use tilemaps? 0 Answers

Can someone help me.. I'm trying to use the button it works! but the problem is I can't put limits with the Y position it keeps moving even it reaches the value of minheight and maxheight thanks. 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