t1 / TFDContents / Assets / 01.Script / 01.MultyInteraction / Player.cs @ 11
이력 | 보기 | 이력해설 | 다운로드 (1.79 KB)
| 1 | 11 | YCH | using System.Collections;  | 
      
|---|---|---|---|
| 2 | using System.Collections.Generic;  | 
      ||
| 3 | using UnityEngine;  | 
      ||
| 4 | |||
| 5 | public class Player : MonoBehaviour  | 
      ||
| 6 | {
 | 
      ||
| 7 | |||
| 8 | MeshRenderer meshRenderer;  | 
      ||
| 9 | |||
| 10 | // Use this for initialization  | 
      ||
| 11 | void Start()  | 
      ||
| 12 |     {
 | 
      ||
| 13 | meshRenderer = this.GetComponent<MeshRenderer>();  | 
      ||
| 14 | |||
| 15 | //print(meshRenderer.material.color);  | 
      ||
| 16 | StartCoroutine(FadeIn());  | 
      ||
| 17 | }  | 
      ||
| 18 | |||
| 19 | // Update is called once per frame  | 
      ||
| 20 | void Update()  | 
      ||
| 21 |     {
 | 
      ||
| 22 | |||
| 23 | }  | 
      ||
| 24 | |||
| 25 | bool isHide = false;  | 
      ||
| 26 | |||
| 27 | IEnumerator FadeIn()  | 
      ||
| 28 |     {
 | 
      ||
| 29 | float value = 0;  | 
      ||
| 30 | |||
| 31 | while (true)  | 
      ||
| 32 |         {
 | 
      ||
| 33 | |||
| 34 | if (isHide == true)  | 
      ||
| 35 |             {
 | 
      ||
| 36 | break;  | 
      ||
| 37 | }  | 
      ||
| 38 | |||
| 39 | value = Mathf.Lerp(value, 1, Time.deltaTime * 0.5f );  | 
      ||
| 40 | |||
| 41 | //print(value);  | 
      ||
| 42 | //GetComponent<MeshRenderer>().material.color = new Color(GetComponent<MeshRenderer>().material.color.r, GetComponent<MeshRenderer>().material.color.g, GetComponent<MeshRenderer>().material.color.b, value);  | 
      ||
| 43 | |||
| 44 | meshRenderer.material.color = new Color(meshRenderer.material.color.r, meshRenderer.material.color.g, meshRenderer.material.color.b, value);  | 
      ||
| 45 | yield return null;  | 
      ||
| 46 | |||
| 47 | }  | 
      ||
| 48 | }  | 
      ||
| 49 | |||
| 50 | public void Hide()  | 
      ||
| 51 |     {
 | 
      ||
| 52 | StartCoroutine(FadeOut());  | 
      ||
| 53 | }  | 
      ||
| 54 | |||
| 55 | IEnumerator FadeOut()  | 
      ||
| 56 |     {
 | 
      ||
| 57 | float value = 1;  | 
      ||
| 58 | |||
| 59 | isHide = true;  | 
      ||
| 60 | |||
| 61 | while (true)  | 
      ||
| 62 |         {
 | 
      ||
| 63 | value = Mathf.Lerp(value, 0, Time.deltaTime * 0.9f);  | 
      ||
| 64 | |||
| 65 | meshRenderer.material.color = new Color(meshRenderer.material.color.r, meshRenderer.material.color.g, meshRenderer.material.color.b, value);  | 
      ||
| 66 | |||
| 67 | |||
| 68 | if (value <= 0.01)  | 
      ||
| 69 |             {
 | 
      ||
| 70 | isHide = false;  | 
      ||
| 71 | Destroy(gameObject);  | 
      ||
| 72 | break;  | 
      ||
| 73 | }  | 
      ||
| 74 | |||
| 75 | yield return null;  | 
      ||
| 76 | }  | 
      ||
| 77 | }  | 
      ||
| 78 | }  |