한 걸음 두 걸음

unity UI Image 변경 본문

Unity

unity UI Image 변경

언제나 변함없이 2019. 4. 17. 22:50
반응형

충돌 발생할 때마다 HP 줄어들다가 이미지 따란~하고 나타나게 하는 코드

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class Sound : MonoBehaviour {
	public AudioClip sndExp;
    public Text countText;
    public Image image;

    private int count = 100;

    void OnCollisionEnter(Collision coll)
    {
        if (coll.gameObject.CompareTag("pacman"))
        {
            AudioSource.PlayClipAtPoint(sndExp, transform.position);
            transform.position = new Vector3(43, 3, 40);
            count -= 20;
            setCountText();

        }
        
    }

    void setCountText() {
        countText.text = "Pacman HP : " + count.ToString();
        if (count <= 0)
        {
            countText.text = "게임 종료";
            image.enabled = true;
        }

    }
    // Use this for initialization
    void Start () {
        image.enabled = false;

    }
	
	// Update is called once per frame
	void Update () {
	
	}
}
반응형