Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Animation won't play after moving an object. Can't figure this one out

Discussion in 'Editor & General Support' started by Ded_Hed_Hyde, Apr 8, 2014.

  1. Ded_Hed_Hyde

    Ded_Hed_Hyde

    Joined:
    Mar 10, 2014
    Posts:
    22
    Been at this for hours now and finally decided to see if I could get some help. I simply want to move an object from point A to point B. No problem got that. Once the gameobject is there i want it to play its animation. Problem. It has two animations. Idle and working. Once it gets to point B it's supposed to start animating but nothing. It's using simple Legacy animations and they work fine until i try to start them in script. Any help would be appreciated.

    Code (csharp):
    1. //Inspector variables
    2. public var costToBuild       :float;                    //cost to build the rig
    3. public var timeToBuild       :float;                    //time it takes rig to be built
    4. public var upTime            :int;                      //amount of time rig has operated
    5. public var maintCost         :float;                    //daily cost to maintain rig properly
    6. public var safetyRating      :int;                      //overall safety rating of the rig. Affects every aspect of the rig
    7. public var epaImpact         :int;                      //Impact rig has on enviroment
    8. public var contractLength    :int;                      //Current length of this rigs contract
    9. public var personsOnboard    :int;                      //How many people are employed and work on the rig
    10. public var basePay           :int;                      //base payment of each crew member on board
    11. public var workDesire        :int;                      //This is the overall desire of the rig which affects personnal willing to work on the rig
    12. public var totalOccupy       :int;                      //Complete occupants
    13. public var drillingSpeed     :int;                      //How fast a rig drills each day
    14. public var generation        :int;                      //1st generation to 6th
    15. public var totalCost         :float;                    //Total daily cost to run rig. Base cost
    16. public var rigType           :int;                      //1:platform /2:jackup /3:floater /4:semi /5:drillship
    17.  
    18. //Private variables
    19. var isWorking        :boolean = false;          //switch for animations based on rig working or not
    20. var bMove            :boolean = false;
    21.  
    22.  
    23. //Game Loop
    24. function Update ()
    25. {
    26.     var wellMoveTo : Transform = GameObject.Find("shallowwell_02").transform;
    27.     var Distance : Vector3 = wellMoveTo.transform.position - transform.position;
    28.    
    29.     if(isWorking == false)
    30.     {
    31.         animation.Play("platform_Idle", PlayMode.StopAll);
    32.     }
    33.    
    34.     //Movement code for rigs
    35.     var startPos :Vector3 = gameObject.transform.position;
    36.     var endPos :Vector3 = wellMoveTo.transform.position;
    37.     var dist = Vector3.Distance(transform.position, wellMoveTo.position);
    38.     if(bMove == true)
    39.     {
    40.         transform.position = Vector3.Lerp(transform.position, wellMoveTo.transform.position, Time.deltaTime * 1.0);
    41.        
    42.         print ("Distance to other: " + dist);
    43.         if (dist < 2.0)
    44.         {
    45.             print("should be working");
    46.             animation.Play("platform_Working", PlayMode.StopAll);
    47.             isWorking = true;
    48.             bMove = false;
    49.         }
    50.     }
    51. }
     
  2. Ded_Hed_Hyde

    Ded_Hed_Hyde

    Joined:
    Mar 10, 2014
    Posts:
    22
    Okay nevermind. Figured it out. For some reason my prefab had the script assigned to it twice.