ObjectHit.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ObjectHit : MonoBehaviour
{
    // private은 이 함수가 이 클래스 내에서만 접근할 수 있다는 말임
    // Collision은 부딪힌 대상에 대한 정보가 들어있음
    // 들어왔을 때 충돌을 감지함 (들어올 시점에 1번) - 떨어졌다 다시 부딪치면 다시 감지
    private void OnCollisionEnter(Collision collision)
    {
        Debug.Log("Bumped into a wall");
        // GetComponent메서드
        GetComponent<MeshRenderer>().material.color = new Color(1, 0, 0, 1); // red
    }
}

Collision, GetComponent

 

'유데미 강의 > C#과 Unity로 3D 게임 개발하기 : 장애물 코스' 카테고리의 다른 글

Tag  (0) 2022.08.02
Score, Time.time, If, Rigidbody  (0) 2022.08.02
메서드  (0) 2022.08.02
Collision  (0) 2022.07.28
Cinemachine  (0) 2022.07.28

+ Recent posts