- Home /
Question by
sourna · Jul 29, 2014 at 03:59 AM ·
c#animationgameobject
why not run animation when doublication gameObject ????
Any object that's a single object created in Unity or imported as a single object is going to have this problem whenever its animation includes a position transform. The solution is to put the object with its animation in a group and then move the group.
children inherit the transforms of their parents, and their own animations stay relative to the parent. no parent of that transform exists, it's going to go ahead and instantiate it in the normal place.
why not runing animation when doublication gameObject my code is:
using UnityEngine;
using System.Collections;
public class PowerUp : MonoBehaviour {
public AnimationClip clip;
public AudioClip soundFX;
public int pointValue=5;
public GameObject scoreKeeper;
public GameObject eventFx;
// Use this for initialization
void Start () {
}
// Update is called once per frame
IEnumerator OnTriggerEnter(Collider collider) {
if (collider.tag == "Player"){
animation.Play (clip.name);
scoreKeeper.SendMessage("UpdateScore",pointValue,SendMessageOptions.DontRequireReceiver);
audio.PlayOneShot (soundFX);
yield return new WaitForSeconds(clip.length+1);
Destroy(gameObject);
}
}
public void SpecialEvents()
{
if(!(transform.parent)){
GameObject clone = Instantiate(eventFx,transform.position,transform.rotation)as GameObject;}
else {
GameObject clone = Instantiate(eventFx, transform.parent.position,transform.rotation)as GameObject;}
}
}
capture.jpg
(15.2 kB)
Comment