Search Unity

Different Ways To Animate

Discussion in 'Scripting' started by LeftyGuitar, Aug 1, 2015.

  1. LeftyGuitar

    LeftyGuitar

    Joined:
    May 4, 2015
    Posts:
    19
    Hello,

    So I was having some trouble trying to play animations in Unity. I'm wondering if there is a different way to animate game objects in Unity, or if it is possible to animate them, like the images one by one. Any help would be appericated. I am mostly looking how to animate 2D objects and I'm using C#. If some one could give an example, that would be great.


    I've added some pics and some code to show what I am trying to do. I picked up the work after someone else had done some of the other work.




    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Target : MonoBehaviour {
    5.  
    6.     // Use this for initialization
    7.  
    8.     [SerializeField]
    9.     Animation DarkWomanSuitAni;
    10.     Animation Splash;
    11.  
    12.     void Start () {
    13.         //DarkWomanSuitAni = new Animation();
    14.     }
    15.  
    16.  
    17.  
    18.     // Update is called once per frame
    19.     void Update () {
    20.         if(GameObject.FindGameObjectWithTag("lightwoman1"))
    21.         {
    22.             gameObject.SetActive(true);
    23.         }
    24.     }
    25.  
    26.  
    27.  
    28.     void OnCollisionEnter(Collision col) {
    29.  
    30.  
    31.         if (col.gameObject.CompareTag ("ball")) {
    32.  
    33.             // SEND MESSAGE HERE
    34.             Debug.Log("TARGET HIT: trigger animation and poin increase here");
    35.             this.GetComponent<Animation>().Play("target_hit");
    36.             //this.GetComponent<Player>().dunks++;
    37.  
    38.             //this.GetComponent<Animation>().Play("SeatFlip");
    39.             //col.gameObject.GetComponent<Animation>().Play("LightWomanAni");
    40.    
    41.             DarkWomanSuitAni.Play("DarkWomanSuitAni");
    42.             //Splash.Play("Splash_2");
    43.            
    44.              //col.gameObject.GetComponent<Animation>().Play("LightWomanAni");
    45.              SoundManager.Instance.PlaySound("splash");
    46.  
    47.             // ignores collision with ball after being hit once
    48.             // (to prevent multiple hits from the same ball)
    49.             Physics.IgnoreCollision(this.GetComponent<Collider>(), col.collider);
    50.         }
    51. }
     
    Last edited: Aug 1, 2015