• 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
Question by conconexplosion · Aug 07, 2013 at 03:59 PM · audioslenderpages

Audio Wont Play In Page Script

I am using a code from majestics slender kit.... I am editing it to play music and stop it depending on how many pages have ben collected. the audio wont play for some reason... anyone know what i did wrong???? i am new to coding so please be patient with me... thanks

 #pragma strict
     @script RequireComponent( AudioSource )
      
     var pages : int = 0;
     var pagesToWin : int = 8;
     var distanceToPage : float = 2.5;
      public var pagePickup : AudioClip;
      var theEnemy : EnemyScript;
      
      public var FirstPage : AudioClip;
      public var thirdpage : AudioClip;
      public var FifthPage : AudioClip; 
      public var SeventhPage : AudioClip;
     
     function Start()
     {
     Screen.lockCursor = true;
      
     // find and store a reference to the enemy script (to reduce distance after each paper is collected)
     if ( theEnemy == null )
     {
     theEnemy = GameObject.Find( "Enemy" ).GetComponent( EnemyScript );
     }
     }
      
      
     function Update()
     {
     //if ( Input.GetMouseButtonUp(0) ) // use E in editor as LockCursor breaks with left mouseclick
     if ( Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.E) )
     {
     //var ray = Camera.main.ScreenPointToRay( Input.mousePosition ); // always cast ray from center of screen
     var ray = Camera.main.ScreenPointToRay( Vector3( Screen.width * 0.5, Screen.height * 0.5, 0.0 ) );
     var hit : RaycastHit;
     if ( Physics.Raycast( ray, hit, distanceToPage ) )
     {
     //if ( hit.collider.gameObject.tag == "Paper" )
     if ( hit.collider.gameObject.name == "Page" )
     {
     pages += 1;
     //Debug.Log( "A Page was Collected. Total papers = " + papers );
      
      audio.PlayClipAtPoint( pagePickup, transform.position );
       Destroy( hit.collider.gameObject );
      
      if ( pages==1 )
    audio.PlayClipAtPoint( FirstPage, transform.position );
    }
     if ( pages==3 )
    {
    audio.Stop();
    audio.PlayClipAtPoint( thirdpage, transform.position );
    audio.Play();
    }
     if ( pages==5 )
    {
    audio.Stop();
    audio.PlayClipAtPoint( FifthPage, transform.position );
    audio.Play();
    }
     if ( pages==7 )
    {
    audio.Stop();
    audio.PlayClipAtPoint( SeventhPage, transform.position );
    audio.Play();
    }
     // make enemy follow closer
     theEnemy.ReduceDistance();
     }
     }
     }
     
     
      
     function OnGUI()
     {
     if ( pages < pagesToWin )
     {
     GUI.Box( Rect( (Screen.width * 0.5) - 60, 10, 120, 25 ), "" + pages.ToString() + " Pages" );
     }
     else
     {
     GUI.Box( Rect( (Screen.width/2)-100, 10, 200, 35 ), "All Pages Collected!" );
     // Application.LoadLevel( "sceneWin" );
      }
      }
Comment

People who like this

0 Show 3
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 perchik · Aug 07, 2013 at 04:28 PM 0
Share

Can you clarify, what are you expecting to happen and what is actually happening?

avatar image awesomeaustin316 · Aug 07, 2013 at 04:33 PM 0
Share

Do you have the audio source attached to the same object as the first script?

avatar image conconexplosion · Aug 07, 2013 at 06:53 PM 0
Share

@awesomeaustin316 @perchik I Made an epic fail because i forgot to put in the audio XD.. but now the audio wont stop.... any help? Edit: now it only plays where the page picked up... wtf am i doing wrong?

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

16 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

Related Questions

do you know what version of unity was released in the end of 2012? 0 Answers

Slender - Collecting papers with left mouse click? 1 Answer

Music Wont Stop From Page Script+ Extra Problom 1 Answer

Slender type game 1 Answer

Dynamic Audio Mixing? 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