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 gianni123 · May 18, 2010 at 11:06 AM · animationaudiotriggeractivate

activate audio / animation on trigger

how to activate audio/animation with the script "activate trigger"?

how to set the script?

alt text

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

2 Replies

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

Answer by Mike 3 · May 18, 2010 at 03:13 PM

Something along the lines of this:


function OnTriggerEnter()
{
    if (action == Action.Enable)
    {
        target.animation.Play();
    }
    else if (action == Action.Animate)
    {
        target.audio.Play();
    }
}

Edited so that it'll work no matter which component you use for target

It should just work in your script (I'm not sure what the exact variables are and if you're using enums for the actions, but those should be fixable easily)

Edit 2, using your own code... Edited it a little so that it's less prone to breaking:

using UnityEngine;

public class ActivateTrigger : MonoBehaviour { public enum Mode { Trigger = 0, // Just broadcast the action on to the target Replace = 1, // replace target with source Activate = 2, // Activate the target GameObject Enable = 3, // Enable a component Animate = 4, // Start animation on target Deactivate= 5 // Decativate target GameObject }

/// The action to accomplish public Mode action = Mode.Activate;

/// The game object to affect. If none, the trigger work on this game object public Object target; public GameObject source; public int triggerCount = 1;/// public bool repeatTrigger = false;

void DoActivateTrigger() { --triggerCount;

if (!(target is Component || target is GameObject)) return;

if (triggerCount == 0 || repeatTrigger) { GameObject targetGameObject = target.gameObject;

  switch (action)
  { 
     case Mode.Trigger: 
        targetGameObject.BroadcastMessage ("DoActivateTrigger"); 
        break; 
     case Mode.Replace: 
        if (source != null)
        { 
           Object.Instantiate (source, targetGameObject.transform.position, targetGameObject.transform.rotation); 
           DestroyObject (targetGameObject); 
        } 
        break; 
     case Mode.Activate: 
        targetGameObject.active = true; 
        break; 
     case Mode.Enable: 
        if (target is Behaviour) 
           ((Behaviour)target).enabled = true; 
        break;    
     case Mode.Animate: 
        targetGameObject.animation.Play (); 
        break;    
     case Mode.Deactivate: 
        targetGameObject.active = false; 
        break; 
  } 

}

} void OnTriggerEnter (Collider other) { DoActivateTrigger (); } }

Comment
Add comment · Show 6 · 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 gianni123 · May 18, 2010 at 10:16 PM 0
Share

this solution dont work..how to set this script or the activate trigger script can you make a concrete example?

the animation target is: messoplayer the animation is: watertouch the soundsource is sound1 the sound is audioprova

thank you

avatar image Mike 3 · May 18, 2010 at 10:56 PM 0
Share

edited, if it still doesn't work you'll need to paste the activate trigger script - that's as close as i can get it without seeing it

avatar image gianni123 · May 18, 2010 at 11:18 PM 0
Share

here's the script.. http://forum.unity3d.com/viewtopic.php?p=320196#320196

thank you!

avatar image gianni123 · May 18, 2010 at 11:25 PM 0
Share

a screenshot http://img3.imageshack.us/i/immaginerq.jpg/

avatar image gianni123 · May 19, 2010 at 05:19 PM 0
Share

you see the script?

Show more comments
avatar image
0
Best Answer

Answer by gianni123 · May 22, 2010 at 10:33 AM

animation solved:

var animateobject: GameObject;

function OnTriggerEnter (collision : Collider)

{

if (collision.gameObject.tag == "Player") //

{

   animateobject.animation.CrossFade ("animationname");

} }

audio solved:

using the "activate trigger" script with replace option

image

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

stop triggers from retriggering animation 2 Answers

Trying to play other objects' sound and animations from Raycast hit 1 Answer

Play Animation OnTriggerEnter 2 Answers

Wanting audio to pause when entering a trigger zone 1 Answer

Problem tags to 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