etc-posts/Unity :: C# 튜토리얼

[유니티C#][AR] 누르면 색변하는 차 만들기.1

플라즈밍 2019. 1. 12. 18:04
반응형

버턴누르면 차색깔 바뀌게 만들기


- 차의 머티리얼을 가져옴

- 차를 누르면 콜리젼이 발생하도록 콜리젼 엔터에 색을 변화시키는 함수를 작성



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
30
31
32
33
34
35
36
 
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
 
public class CarColorChange : MonoBehaviour {
 
    //실제 에셋의 메터리얼을 가져오는 경우이다.
    public Material mat = null;
 
    // Use this for initialization
    void Start () {
        //에셋의 메터리얼을 바꾼다. 
        //이 메터리얼을 참조하는 모든 게임오브젝트들도 영향을 받는다.
        mat.color = Color.red;
        
    }
    public void ChangeColor()
    {
        float r = Random.Range(0.5f, 1);
        float g = Random.Range(0.5f, 1);
        float b = Random.Range(0.5f, 1);
 
        mat.color = new Color(r, g, b, 1);
    }
    public void ChangeColorRef(Image img)
    {
        mat.color = img.color;
    }
    // Update is called once per frame
    void Update () {
        
    }
}
 
cs


반응형