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.
GameObject Pic
Prefab for GameObject
Prefab for target
using UnityEngine;
using System.Collections;
public class Target : MonoBehaviour {
// Use this for initialization
[SerializeField]
Animation DarkWomanSuitAni;
Animation Splash;
void Start () {
//DarkWomanSuitAni = new Animation();
}
// Update is called once per frame
void Update () {
if(GameObject.FindGameObjectWithTag("lightwoman1"))
{
gameObject.SetActive(true);
}
}
void OnCollisionEnter(Collision col) {
if (col.gameObject.CompareTag ("ball")) {
// SEND MESSAGE HERE
Debug.Log("TARGET HIT: trigger animation and poin increase here");
this.GetComponent<Animation>().Play("target_hit");
//this.GetComponent<Player>().dunks++;
//this.GetComponent<Animation>().Play("SeatFlip");
//col.gameObject.GetComponent<Animation>().Play("LightWomanAni");
DarkWomanSuitAni.Play("DarkWomanSuitAni");
//Splash.Play("Splash_2");
//col.gameObject.GetComponent<Animation>().Play("LightWomanAni");
SoundManager.Instance.PlaySound("splash");
// ignores collision with ball after being hit once
// (to prevent multiple hits from the same ball)
Physics.IgnoreCollision(this.GetComponent<Collider>(), col.collider);
}
}
}