728x90
unityNullReferenceError
- ์ ๋ํฐ์์ Raycast ์คํฌ๋ฆฝํธ ์ ์ฉ ์
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ObjectTouchEvent : MonoBehaviour
{
// Update is called once per frame
void Update()
{
ClickDetect();
}
private void ClickDetect()
{
if (Input.GetMouseButtonDown(0))
{
Debug.Log("Click ButtonDown(0)");
RaycastHit hit_info;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit_info, Mathf.Infinity))
{
Debug.Log("์ ์ฌ๊ธฐ๋ ์๋ค์ด์ค๋๊ฐ?");
Debug.Log(hit_info.collider.gameObject.name);
}
}
}
}
์ ๋ํฐ ์คํ ํ
- NullReferenceException: Object reference not set to an instance of an object
ํด๊ฒฐ๋ฐฉ๋ฒ
- main Camera์ Tag๋ฅผ MainCamera๋ก ์์ ํ๋ค.
'Error' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Git] Directory์ ์ ๊ทผ์ด ์๋ ๋ (0) | 2021.09.21 |
---|---|
[Unity] ํจ์ ํธ์ถ์ ๋ฆ์ถฐ์ฃผ๋ Invoke (0) | 2021.08.31 |
[Windows] cmd์์ clear ls ์ฌ์ฉ๋ฒ (0) | 2021.08.30 |
[Linux] omitting directory (0) | 2021.08.24 |
Tistory markdown ๊ธ์ ๊นจ์ง (0) | 2021.08.17 |