- Home /
 
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?
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();
 
              Your answer
 
             Follow this Question
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