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


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;
        }
    }
}