My animation doesn’t play when this object is instantiated, I’m at a loss? Can you see anything wrong with this? I have one animation attached to the object.
public class killspritescript : MonoBehaviour {
Animation anim;
// Use this for initialization
void Start () {
anim = GetComponent<Animation>();
Invoke("destroyme", 4);
}
// Update is called once per frame
void Update () {
if(!anim.isPlaying)
{
anim.Play(); // no animation is played?
}
}
private void destroyme()
{
Destroy(gameObject);
}
}
Not sure why it’s not playing, but I do see that you could just play it in Start().
Also, you can delay ‘Destroy’ if you’re doing nothing special , other than waiting some amount of time.
If you remove Invoke and just write 'Destroy(gameObject, 4); ’ it’s the same thing
From the code you posted, you have put an animation clip directly on your Object, I do not think this is supported anymore, you need to use an Animation Controller :
True, it is in the docs, I have just made a test scene and put an animation clip directly on the GO, used the OP code, and it does not work. I opened up the anim file and changed it to a legacy animation, and then the code does work, kinda, ( the animation goes into playing state, but the animation does not actually play in the editor)
Weird one for me, Will probably be sat here for 2 hours now trying to get it working lol
Well, all I have learned in my 5 mins is that I could use a lot of practice even with the world’s simplest animation (creation) lol.
However, I was able to create an animation that played.
Plus, after I did that, I noticed there is a play automatically button haha. So that bit of code to start it may not even matter.
I did have to change mine to legacy, also.
Not sure what else is wrong, sorry
Thank you Just need a cool generic ‘monster die’ animation.
Will be putting website up for the game soon, game is procedurally generated 2d game where you are falling down a very long hole (think downwell game) but a lot longer Going to put puzzle elements into it too, it is looking good so far and runs on Android 60fps and PC/Linux. I’d port it to Mac/iPhone too if I had a mac!
I’ve attached two screen shots. Every time game is run, the scenery, aliens etc are all procedurally generated and it only uses 8 game objects for the massive levels :-), each game object is a massive mesh I generate.
Optimised the shooting and put some nice light animation in when bullet hits platforms. Just need have some breakable platforms in, thus if shoot platform which is part of mesh, make those vertices disappear…