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 AusAndrew19 · Jul 02, 2012 at 07:58 PM · teleport

how to add a sound to this script

Hi Guys. I'm Using this teleport script

 using UnityEngine;

public class Teleporter : MonoBehaviour { public Transform exit; static Transform last;

 void OnTriggerEnter ( Collider other )
 {
     if ( exit == last )
         return;

     TeleportToExit( other );
 }

 void OnTriggerExit ( )
 {
     if ( exit == last )
         last = null;
 }

 void TeleportToExit ( Collider other )
 {
     last = transform;
     other.transform.position = exit.transform.position;
 }

}

How would i go about adding a teleport sound to it. I thought it would be like

var teleportsound: AudioClip;

then down the bottom i would add

audio.PlayOneShot(teleportSound);

But this does not work it says Parse error. Could this be because the script is C# and maybe the audio part isnt? please help :) thanks

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

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by AlucardJay · Jul 02, 2012 at 08:02 PM

yep, the C# should be :

 public AudioClip teleportSound;

 audio.PlayOneShot(teleportSound);

(check your spelling of teleportSound, one has teleportsound and the other has teleportSound !)

EDIT : included into your script :

 using UnityEngine;
 
 public class Teleporter : MonoBehaviour { 
 
   public Transform exit; 
   static Transform last;
  
   public AudioClip teleportSound;
 
   void OnTriggerEnter ( Collider other )
   {
       if ( exit == last )
           return;
 
       TeleportToExit( other );
   }
 
   void OnTriggerExit ( )
   {
       if ( exit == last )
       last = null;
   }
 
   void TeleportToExit ( Collider other )
   {
       last = transform;
       other.transform.position = exit.transform.position;
  
       audio.PlayOneShot(teleportSound);
   }
 
 }
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
avatar image
0

Answer by AusAndrew19 · Jul 03, 2012 at 08:11 AM

I'm Getting a error at line 2. A namespace can only contain types and namespace declorations. This is how i implemented it.

using UnityEngine;

public AudioClip teleportSound;

public class Teleporter : MonoBehaviour { public Transform exit; static Transform last;

 void OnTriggerEnter ( Collider other )
 {
     if ( exit == last )
         return;

     TeleportToExit( other );
 }

 void OnTriggerExit ( )
 {
     if ( exit == last )
         last = null;
 }

 void TeleportToExit ( Collider other )
 {
     last = transform;
     other.transform.position = exit.transform.position;

audio.PlayOneShot(teleportSound); } }

Info will be appreciated thanks.

Comment
Add comment · Show 5 · 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 diddykonga · Jul 03, 2012 at 08:14 AM 1
Share

You cant declare variables outside of a class :)

avatar image AusAndrew19 · Jul 03, 2012 at 09:05 AM 0
Share

Can you help me declare it properly?

avatar image AlucardJay · Jul 03, 2012 at 09:05 AM 0
Share

did you check the edit of my answer? (am $$anonymous$$ $$anonymous$$ay)

avatar image AusAndrew19 · Jul 03, 2012 at 09:12 AM 0
Share

Oh mate thank you! i didnt see that all. Sorry :) Thank you heaps. This works completely. thank you buddy :)

avatar image AlucardJay · Jul 03, 2012 at 09:17 AM 0
Share

np. just remember to use comments, and mark an answer that works for future readers (click on the Tick under the thumbs, next to the answer that works)

avatar image
0

Answer by AusAndrew19 · Jul 03, 2012 at 08:42 AM

could you help me put it in a class? Im confused.

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 AlucardJay · Jul 03, 2012 at 08:51 AM 0
Share

@AusAndrew19 , please use the [add new comment] button to add comments.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Teleport enemy after player collides with an object? 0 Answers

How to make a cooldown on a script 1 Answer

When do we need to use Class? 1 Answer

hide object start script 4 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