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
1
Question by Dan Jimenez · Sep 02, 2010 at 06:04 PM · animationguisound

Play animation and sound when GUI button is pressed

I have a GUI button that I have created. When the button is pressed I would like a game object to play a certain animation and also play a sound. I created the animation in Unity. Here is the script I have written for the GUI button.

static var triggerGo: int;

function OnGUI () { //Make a background box GUI.Box (Rect (500,120,100,90), "");

//Make the first button
if (GUI.Button (Rect(510,150,80,20),  "Lever")){
} 

}

The animation clip I created using keyframe animation in Unity is called lever1 and the soundclip is called lever.wav

I am still new to writing script. Can someone please show me how and where to place the animation and sound into the script from above? Thanks

Comment
Add comment · Show 1
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 nowhereman · Dec 31, 2010 at 06:46 AM 0
Share

$$anonymous$$ay I suggest you select an answer, if you think the answer you got is the correct one. This question just got bumped by the magical monkeys that operate everything around here because you have not selected an answer

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by joedrigon · Sep 02, 2010 at 06:21 PM

var lever : AudioClip;

if (GUI.Button (Rect(510,150,80,20), "Lever")) { animation.Play ("lever1"); audio.PlayOneShot(lever); }

Read this because I'm not sure what I have posted is 100% correct...

http://unity3d.com/support/documentation/ScriptReference/Animation.Play.html http://unity3d.com/support/documentation/ScriptReference/AudioSource.PlayOneShot.html

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

No one has followed this question yet.

Related Questions

How to plot velocity of vehicle wheel collider on realtime graph 0 Answers

Custom AsyncOperation to show LoadingImage for slowish XML conversion & email upload method in Unity? 1 Answer

CoolDown Animation on the GUI 1 Answer

Animation + sound on collision 1 Answer

Linking sountrack to the start of an animation 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