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 ospfranco · Jul 17, 2014 at 02:03 AM · animationanimatortriggers

how to get current gameObject animator triggers?

Hey I'm making a simple number game, I have created a prefab object with the a number at it's animations and saved it as a prefab, I have two triggers: - taped - untaped

However when I created the next prefab for other number (with the same triggers) somehow they are all getting called. I have two scripts:

Number Script:

 #pragma strict
 
 private var anim:Animator;
 private var tapped:boolean = false;
 
 var value:int;
 
 
 function Start () {
     anim = GetComponent("Animator") as Animator;
 }
 
 function Update () {
 }
 
 function tap() {
   if(!tapped) {
     anim.SetTrigger("taped");
     tapped = true;
   } else {
     anim.SetTrigger("untaped");
     tapped = false;
   }
 }

and my InputHandler script:

 #pragma strict
 private var numberScript:numberScript;
 
 function Start () {
     numberScript = gameObject.GetComponent("numberScript");
     Debug.Log("I'm atached to a numberScript with value: " + numberScript.value);
 }
 
 function Update () {
   if(Input.GetMouseButtonDown(0)){
     var mousePosition : Vector2 = Camera.main.ScreenToWorldPoint(Input.mousePosition);
     var hitCollider : Collider2D = Physics2D.OverlapPoint(mousePosition);
     Debug.Log("mouse pos "+mousePosition.x+" y "+mousePosition.y+" ");  
     if(hitCollider){  
       Debug.Log("Hit " + hitCollider.transform.name + " x " + hitCollider.transform.position.x + " y " + hitCollider.transform.position.y);  
       numberScript.tap();
     }
   }
 }

Any ideas what might be happening?

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

1 Reply

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

Answer by smallbit · Jul 17, 2014 at 03:00 AM

I think You should be addressing only the script on the tapped object like this (line 16) (

 hitCollider.gameObject.GetComponent<numberScript>().tap();

instead of this

 numberScript.tap();

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 ospfranco · Jul 19, 2014 at 03:43 PM 0
Share

Thank you! that worked!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

2D Animation does not start 1 Answer

Animation Trigger playing twice 8 Answers

How do I setup a Shooting Trigger to make an Animation play on a Platform? 0 Answers

Problem with Animation triggring 0 Answers

making a chair animate float and fall 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