+ 이 글은 작성자가 직접 공부하고 복습하며 작성한 글입니다. 만약 직접 작성하지 않았다면, 꼭 출처를 밝히겠습니다!

 + 이 글은 개인적인 공부를 바탕으로 작성되었기에, 틀린 부분이 있을 수 있으며, 틀린 부분이 있다면 알려주시면 감사하겠습니다!

 + 이 글을 다른 곳으로 가져가신다면, 꼭 출처를 남겨주세요~

 + '참고사이트'는 공부하기 위해 참고한 사이트들을 모아 둔 것입니다.

 + 혹시라도 문제가 된다면 바로 조취를 취할테니, 말해주시면 감사하겠습니다!


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//Attach this script to an Image GameObject and set its Source Image to the Sprite you would like.
//Press the space key to change the Sprite. Remember to assign a second Sprite in this script's section of the Inspector.
 
using UnityEngine;
using UnityEngine.UI;
 
public class Example : MonoBehaviour
{
    Image m_Image;
    //Set this in the Inspector
    public Sprite m_Sprite;
 
    void Start()
    {
        //Fetch the Image from the GameObject
        m_Image = GetComponent<Image>();
    }
 
    void Update()
    {
        //Press space to change the Sprite of the Image
        if (Input.GetKey(KeyCode.Space))
        {
            m_Image.sprite = m_Sprite;
        }
    }
}
cs





Copyright © -강정이좋아- 무단 전재 및 재배포는 하지 말아주세요.

'요리 레시피 > Unity' 카테고리의 다른 글

Script에서 Resource가져오기  (0) 2018.06.12
Script에서 Mouse 입력 설정하기  (0) 2018.06.12
[Unity] rigidbody.velocity  (0) 2018.05.14
[UGUI] Progress Bar - Slider  (0) 2018.04.06
[UGUI] NGUI -> UGUI  (0) 2018.04.06

+ Recent posts