Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.UI;
- [RequireComponent(typeof(Button))]
- [ExecuteInEditMode]
- public class ButtonCopyStyleFrom : _MonoBehaviour
- {
- public Button ButtonSource;
- public Image ImageSource;
- public bool CopyColors = true;
- public bool CopyImage = true;
- // note that this is only done when the button is enabled. If you want it more dynamic, trigger off a different event
- public void OnEnable()
- {
- if (ButtonSource != null)
- {
- if ((ImageSource == null) && CopyImage)
- ImageSource = ButtonSource.GetComponent<Image>();
- GetComponent<Button>().colors = ButtonSource.colors;
- }
- if ((ImageSource != null) && CopyImage)
- {
- GetComponent<Image>().sprite = ImageSource.sprite;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment