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 therealjackwalden · Apr 23, 2012 at 03:19 PM · animationtrigger

Triggering an animation via distance

Hi there,

Please be aware that im a complete unity noob so please talk to me like an idiot.
I was wondering how i could trigger an animation on an object by coming into close proximity to that object. The animation along with the modeling has been done in 3ds max.

Comment
Add comment · Show 2
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 DaveA · Apr 23, 2012 at 03:22 PM 1
Share

Use the Search feature to look for proximity, plenty of answers

avatar image ocimum · Oct 23, 2015 at 08:05 AM 0
Share

What have you tried? Please use the search feature next time!

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by stingman · Apr 23, 2012 at 06:02 PM

Here's something to get you started. Attach this JavaScript to your player and mess around with it... the target is the object you want to have distance between your player. The detectRange is a variable to determine the distance between the player and the target at which the animation will be triggered.:

 var target : Transform;
 var dodecahedron : GameObject;
 var detectRange: float = 30;
 
 function Update() {
 var tgtDirection = target.position - transform.position;  
 var tgtDistance = tgtDirection.magnitude;
 if (tgtDistance <= detectRange) {
 dodecahedron.animation.Play("NameOfYourObject'sAnimation");
 }
 }


Hope this helps you.

Comment
Add comment · Show 4 · 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 therealjackwalden · Apr 25, 2012 at 02:02 PM 0
Share

just a quick question - where abouts do I place my object into that script? The object in question named in unity as 'dodecahedron'

avatar image stingman · Apr 25, 2012 at 08:37 PM 0
Share

edited my answer with what you need. just drop your "Dodecahedron" game object into the variable slot in the inspector.

avatar image Stealth_Crab_Interactive · Oct 23, 2015 at 07:49 AM 0
Share

how would I go about doing this in C#?

avatar image ocimum Stealth_Crab_Interactive · Oct 23, 2015 at 08:07 AM 0
Share

Have you done one of the tutorials before? $$anonymous$$ost of the time its the same code in c#, you just have to change the way you set up variables!

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

7 People are following this question.

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

Related Questions

trigger animation problems 2 Answers

Triggering a basic animation via Box Collider 4 Answers

Light animation and Main Menu animation at same time from 1 trigger 0 Answers

Multiple animation with One Trigger ?!! 1 Answer

Issues with Animator Controller - Trigger does not reset to false after being set with SetTrigger 2 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