- Home /
how to make one script with different animations attached
Okay so this is my first post. Anyway I made a script:
using UnityEngine;
using System.Collections;
public class MusicOnOff : MonoBehaviour
{
private bool Trigger = false;
public GameObject Button;
public GameObject Speaker;
Transform DoorGameObject;
private bool HasTriggerBeenUsed = false;
void OnTriggerStay ()
{
if (Input.GetKeyDown("f") && !HasTriggerBeenUsed)
{
// toggle audio on/off on audiosource of speakers
AudioSource source = Speaker.GetComponent<AudioSource>();
source.enabled = !source.enabled;
{
Trigger = true;
if (Trigger)
Button.animation.Play ("Buttondown");
}
}
}
}
and where it says: Button.animation.Play ("Buttondown");
I want to be able to edit the animation so it can be changed easily like making it a public GameObject kind of and the script would not have to be edited. If this can't be done I can always try something else though.
The script also may not be great it is my first script made by myself it was probably one of the simplest things I could make so if it could be left the way it is it would also be appreciated.
yep :)
Why do you want to edit the animation ? If you want different animations, create different animations, and play the one you want. But do you really want an animation on a button ??
Yeah I want different animations. I wanted the buttons to go down like you're pressing it except there is more than one button. This means if I use the same animation script to make the button go down it'll teleport to the position of the other button. Hard to explain. Yeah I could do what you said but that'd require more scripts and.. Well I have 13 buttons
Answer by KiraSensei · Oct 10, 2013 at 01:39 PM
I understand your problem.
Maybe you don't need animations at all. Maybe you can use THIS. It will help you move your button from a position to another smoothly. If not, I'm afraid you'll have to make different scripts, or at least one script containing the handling of the 13 buttons at once ...
Answer by Crumpet · Oct 10, 2013 at 02:26 PM
Yeah that looks a lot like what I needed thank you so much anyway on my first post. :D
So please accept my answer by ticking the check next to it :)