How to change a sprite image with script
Tutorial, Unity
0
Learn to change a 2D sprite image from script (C#) in Unity 2018. Unity beginner tutorial.
❤️ Subscribe to Oxmond Tutorials:
https://bit.ly/SubscribeOxmondTutorials
✅ Download 2D Assets Here:
https://assetstore.unity.com/packages/essentials/asset-packs/
✅ Free Packages at the Unity Assets Store:
https://assetstore.unity.com/lists/top-free-packages-13201
😷👕 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
Bird script:
/* .-------. .--. .-------. .--. .--. .--.
| |--.--.--------.-----.-----.--| | |_ _|--.--| |_.-----.----|__|---.-| |-----.
| - |_ _| | _ | | _ | | | | | | _| _ | _| | _ | |__ --|
|_______|__.__|__|__|__|_____|__|__|_____| |___| |_____|____|_____|__| |__|___._|__|_____|
© OXMOND / www.oxmond.com */
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bird : MonoBehaviour
{
public Sprite DeadBird;
void Update()
{
if (transform.position.y >= -4.53)
{
transform.Translate(0f, -0.25f, 0f);
}
else
{
this.gameObject.GetComponent<SpriteRenderer>().sprite = DeadBird;
}
}
}