Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Dublicate a 3D animated prefab with (if hit, play animation) gives me probs

Discussion in 'Scripting' started by dylan2008, Apr 28, 2012.

  1. dylan2008

    dylan2008

    Joined:
    Nov 2, 2011
    Posts:
    10
    Hello,

    i'm making a 3D platform game, and if you Hit an enemy, the enemy plays an animation, it works perfect,

    but if i put some more prefabs of the enemy in the game(yes i updated the prefab), when i hit ONE enemy, all the rest plays the same animation. (it is a rigged character)

    so i want, if you hit enemy 1, enemy 1 does the animation, and if you hit enemy 2 then enemy 2 does the animation. And not all at the same time

    how can i solve this problem

    Greets Dylan
     
  2. dylan2008

    dylan2008

    Joined:
    Nov 2, 2011
    Posts:
    10

    here you can see the two enemies, if i hit the, the must do a "dead" animation
     
  3. dylan2008

    dylan2008

    Joined:
    Nov 2, 2011
    Posts:
    10
    Pleas help me, i am really stuck in this part of the pipeline
     
  4. Ted-Chirvasiu

    Ted-Chirvasiu

    Joined:
    Sep 7, 2010
    Posts:
    381
    Hello!Could you post the code?
    You might be referencing the same GameObject.
     
  5. dylan2008

    dylan2008

    Joined:
    Nov 2, 2011
    Posts:
    10
  6. dylan2008

    dylan2008

    Joined:
    Nov 2, 2011
    Posts:
    10
    Code (csharp):
    1. #pragma strict
    2. static var IsANIMATING = false;
    3. public var IsPushingEnter = false;
    4. static var IPE = 0;
    5. private var m_StartCounter = 0;
    6. private var m_Counter = 0.0;
    7. public var m_TimeLengtOfEnter = 0.8;//0.6
    8. var Explosie: Transform;
    9. private var ObjectPosition : Vector3; // Positie van het object
    10.  
    11. private var m_IsGaanVliegen = 0;
    12. static var m_Gevlogen = 0;
    13.  
    14. function Start () {
    15.  
    16. }
    17. function Update () {
    18. if(IsPushingEnter == true)IPE =1; // IPE = Is Pressing Enter for 1 second long; (i use IPE in other scripts)
    19.         else IPE=0;
    20. if(Input.GetButtonDown("Tornado")) //This is the Attack Button
    21.     {
    22.          m_StartCounter = 1; // Here i am making a counter so that if i press the attack button keeps active for 1 second
    23.     }
    24.   if(m_StartCounter == 1)
    25.     {  
    26.         m_Counter+= Time.deltaTime*1;
    27.     }
    28.   if(m_Counter > 0.1  m_Counter < m_TimeLengtOfEnter)
    29.     {
    30.         IsPushingEnter = true;
    31.     }
    32.   if(m_Counter > m_TimeLengtOfEnter)
    33.     {  
    34.        
    35.         m_StartCounter = 0;
    36.         IsPushingEnter = false;
    37.         m_Counter = 0;
    38.        
    39.    
    40.     }
    41.  if(m_IsGaanVliegen == 1)m_Gevlogen = 1;
    42.      if(m_Gevlogen == 1)GaVliegenAnim(); // If i hit the ATTACK btn then do the function GaVliegenAnim() means Go FlyAnimation
    43.  
    44. }
    45. function OnTriggerStay (col:Collider)
    46. {
    47.     if(IsPushingEnter==true)
    48.     {
    49.     var Exp = Instantiate(Explosie,gameObject.transform.position,Quaternion.identity); //here i make some particles
    50.     m_Gevlogen= 1;
    51.     }
    52. }
    53. function GaVliegenAnim() // AND 1HERE IS THE IMPORTANT CODE, it works on  1 object
    54. {
    55.         IsANIMATING = true; // this i use in a other script so not important
    56.         transform.parent.animation.Play("Spider_Dead"); // here it is play the animation (that works
    57.         yield WaitForSeconds(1.1); //then Destroy the animation after 1.1 sec
    58.         IsANIMATING = false;
    59.         Destroy(transform.parent.gameObject);
    60.         m_IsGaanVliegen = 0; // not important
    61.         m_Gevlogen = 0; // not important
    62.  
    63. }

    This script is attached to Collision_Down, it has a mesh collider with trigger ON

    and this is what it looks like

    click this to see the image bigger : http://i45.tinypic.com/27yu2r5.jpg
     
    Last edited: Apr 29, 2012
  7. Bluntweapon

    Bluntweapon

    Joined:
    Feb 24, 2012
    Posts:
    158
    There's your problem. There's only 1 static variable sitting around, so if the static variable is changed in one script and other scripts reference it...
     
    Last edited: Apr 29, 2012
  8. dylan2008

    dylan2008

    Joined:
    Nov 2, 2011
    Posts:
    10
    thanks you verry much , i am gonna try to solve it now
     
  9. dylan2008

    dylan2008

    Joined:
    Nov 2, 2011
    Posts:
    10
    Thank you So much, the problem is fixed, YES !!!