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
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; } } }
Tags In
Related Posts
Leave a Reply Cancel reply
Tags
2D (2)
3D world (1)
2018 (13)
animation (4)
arrow keys (2)
basic (1)
beginners (13)
bird (1)
blue (1)
C# (11)
change (3)
change image (1)
character (1)
coding (13)
coding pirates (9)
colliders (1)
collision (1)
control (3)
dead (1)
detect (1)
development (13)
flip (1)
game (13)
game making (11)
game making 2D (2)
helicopter (1)
itween (3)
lesson (13)
mouse (1)
move (1)
red (2)
scripting (5)
scripting 2d (3)
small game (1)
sprite (3)
sprites (4)
stopwatch (1)
timer (1)
tricks (1)
tutorials (13)
tweener (2)
tweens (2)
Unity (13)
Unity3d (6)
watch (1)