Changing Color of Gameobject Over a Period of Time
This Unity tutorial show how to change/fade/animate colors over time.
❤️ Subscribe to Oxmond Tutorials. We upload new tutorials every day!
https://bit.ly/SubscribeOxmondTutorials
✅ Download the free Nefertiti 3D statue here:
https://assetstore.unity.com/packages/3d/nefertiti-56818?aid=1100l4p9k
✅ Download the free DOTween here:
https://assetstore.unity.com/packages/tools/animation/dotween-hotween-v2-27676?aid=1100l4p9k
✅ Other Free Assets from the Unity Assets Store:
https://assetstore.unity.com/lists/top-free-packages-13201?aid=1100l4p9k
😷👕 Need a face mask / developer T-shirt? Drop by our shop and get a 20% DISCOUNT on your first purchase by using the discount code OXMONDSALE. Click here:
https://shop.oxmond.com/discount/OXMONDSALE
Set the color script:
/* .-------. .--. .-------. .--. .--. .--. | |--.--.--------.-----.-----.--| | |_ _|--.--| |_.-----.----|__|---.-| |-----. | - |_ _| | _ | | _ | | | | | | _| _ | _| | _ | |__ --| |_______|__.__|__|__|__|_____|__|__|_____| |___| |_____|____|_____|__| |__|___._|__|_____| © 2019 OXMOND / www.oxmond.com */ using System.Collections; using System.Collections.Generic; using UnityEngine; using DG.Tweening; public class ChangeColor : MonoBehaviour { public Material nMaterial; public void SetColorToBlack() { nMaterial.SetColor("_Color", Color.black); } public void SetColorToWhite() { nMaterial.SetColor("_Color", Color.white); } public void SetColorToRed() { nMaterial.SetColor("_Color", Color.red); } public void SetColorToGreen() { nMaterial.SetColor("_Color", Color.green); } }
Fade the color using DOTween:
/* .-------. .--. .-------. .--. .--. .--. | |--.--.--------.-----.-----.--| | |_ _|--.--| |_.-----.----|__|---.-| |-----. | - |_ _| | _ | | _ | | | | | | _| _ | _| | _ | |__ --| |_______|__.__|__|__|__|_____|__|__|_____| |___| |_____|____|_____|__| |__|___._|__|_____| © 2019 OXMOND / www.oxmond.com */ using System.Collections; using System.Collections.Generic; using UnityEngine; using DG.Tweening; public class ChangeColor : MonoBehaviour { public Material nMaterial; public void SetColorToBlack() { nMaterial.DOColor(Color.black, 2); } public void SetColorToWhite() { nMaterial.DOColor(Color.white, 2); } public void SetColorToRed() { nMaterial.DOColor(Color.red, 2); } public void SetColorToGreen() { nMaterial.DOColor(Color.green, 2); } }
[…] Changing Color of Gameobject Over a Period of Time […]