Search Unity

Animator - and states question

Discussion in '2D' started by ade76, Sep 16, 2014.

  1. ade76

    ade76

    Joined:
    Apr 9, 2014
    Posts:
    19
    Hi

    I wondered if someone would be kind enough to help me try and get my head around the "animator'

    I have a main character.... a frog.

    What I need to be able to do is have the frog have a few animations:

    1. Idle
    This I want to be animated using tweens. So i have a tongue etc...all separate body parts that I tween and create a nice loop.

    2. Spin
    When the player touches the character in idle. I want it to jump to a new animation....but this uses essentially a sequence of frames. No tweening it simply runs through pre rendered frames.


    What I'm struggling with is whether the animator system allows for this swap over of "animation techniques". I have seen a lot of examples but they all use the same method (either sprite sheet/pre rendered OR bone based). Is it possible to combine the two so i can use the state controller to handle all this?

    thanks very much in advance
     
  2. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    i think, you can combine them, why not :)

    make frog, add Animator. Create Animator Controller for frog. Drag&Drop this controller on frog´s Animator. Open Animation window. Create animation "Idle". In Animator window set Idle as default animation. Clic "Rec" button in animations window. Use timeline and make animation. In Animation window create new animation "Spin". Drag&Drop your prerendered frames on timeline in Spin animation. In Animator window make transition from Idle to Spin and from Spin to Idle. Create boolean "Touched" in Animator window. Add script for statecontroll to frog. May be with trigger 2D.

    Add box collider 2D to frog. Set it trigger. Make C# script.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Touch : MonoBehaviour {
    5.  
    6.     Animator anim;
    7.    
    8.     void Start () {
    9.         anim = GetComponent <Animator> ();
    10.         }
    11.  
    12.  
    13.     void OnTriggerEnter2D (Collider2D other)
    14.     {
    15.         if (other.gameObject.tag == "Player")
    16.             anim.SetBool ("Touched", true);
    17.             }
    18.  
    19.     void OnTriggerExit2D (Collider2D other)
    20.     {
    21.         if (other.gameObject.tag == "Player")
    22.             anim.SetBool ("Touched", false);
    23.     }
    24.  
    25.  
    26. }
    27.  
    In animator window change transitionscondition:

    idle ->spin, touched true
    spin ->idle, touched false

    and make your player`s tag Player.

    ok, i didnt check it, but you can make something like this.
     
  3. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Have you gotten this to work to you satisfaction? If not, reply here and let us know the state of your project and how we can help.