본문 바로가기

휴지통

Unity / 개인적으로 자주사용하는 함수

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// 해상도 고정
Screen.SetResolution(25601440true);
 
 
// 스크립트내에서 텍스트 내용 편집
public Text ResultScore;
 
var PL = GameObject.Find("Player").GetComponent<Player>();
string Score = PL.score.ToString();
ResultScore.text = Score;
 
 
// 오브젝트 클릭시
using UnityEngine.EventSystems;
 
public class RightArrow : MonoBehaviour,IPointerDownHandler,IPointerUpHandler
{
    public void OnPointerDown(PointerEventData data)
    {
    }
    public void OnPointerUp(PointerEventData data)
    {
    }
}
 
// UI의 위치 변경. 또는 RectTransform 변경
RectTransform RT = (RectTransform)gameObject.transform;
RT.anchoredPosition = new Vector2(00);
 
 
// 트리거 충돌
private void OnTriggerEnter(Collider other)
{
    if (other.tag == "DestroyWall")
}
 
 
// 타 오브젝트 스크립트 저장하기
var GR = GameObject.Find("GameRoot").GetComponent<GameRoot>();
 
 
 
// 타 오브젝트 저장하기
private GameObject Player = null;
Player = GameObject.FindGameObjectWithTag("Player");
 
 
// 타 오브젝트 제거시
DestroyObject(jump);
 
 
// 본인 오브젝트 제거시
Destroy(this.gameObject);
 
 
// 부모 오브젝트를 자신으로 설정
Result.transform.parent = this.transform;
 
 
// 프리팹 생성
Instantiate(Block);
 
 
// 애니메이터 컴포넌트
private const string anime = "animation";
this.animator = GetComponent<Animator>();
this.animator.SetInteger(anime, 9);
 
 
// 컬라이더 충돌
private void OnCollisionEnter(Collision collision)
{
    if (collision.transform.tag == "Block")
}
 
 
// 씬이 넘어가도 오브젝트는 유지되도록
DontDestroyOnLoad(gameObject);
 
 
// 하이드 기능
gameObject.SetActive(false);
false 시 하이드 true시 언하이드
cs