์๋ ๋ฐฐ์น๋ ์ค๋ธ์ ํธ๋ค ์ค์ ํ๊ทธ LightPlace์ธ ์ ๋ค ๋ฐฐ์ด๋ก ๊ฐ์ ธ์์ ๋ฆฌ์คํธ๋ก ๋ณํํ๊ณ
OnMouseButtonDown ๋ฐ์ํ๋ฉด
LightPlaceOn์คํํด์
for๋ฌธ ๋๋ ค์ 1๊ฐ์ SetActive(true)๋๋ฆฌ๋๊ฑด๋ฐ
์๋๊ฐ์์ ๋ฌ๋ง ์ฃผ๊ตฌ ์ฅ์ฐฝ ๋จ๋ค
๋๋ฒ๊ทธ.๋ก๊ทธ(๋ผ์ดํธํ๋ ์ด[i]); ํด๋ ๋๊ฐ์ ์๋ฌ๋ธ
ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) (at <437ba245d8404784b9fbab9b439ac908>:0)
System.ThrowHelper.ThrowArgumentOutOfRangeException () (at <437ba245d8404784b9fbab9b439ac908>:0)
System.Collections.Generic.List`1[T].get_Item (System.Int32 index) (at <437ba245d8404784b9fbab9b439ac908>:0)
TowerMaker.LightPlaceOn () (at Assets/Scripts/UI/TowerMaker.cs:74)
TowerMaker.OnMouseDown () (at Assets/Scripts/UI/TowerMaker.cs:49)
UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32)
list ๋ฒ์ ์ด๊ณผํ๊ฑฐ ๊ฐ์๋ฐ? ๋ฆฌ์คํธ ์ธ๋๋ ์ ๋ ๊ฒ for๋ฌธ์ผ๋ก ๊ฐฏ์ ์ง์ ํ ๊บผ๋ฉด ์ต๋์ซ์๋ฅผ list count๋ฅผ ์จ์ ๊ตฌํ๊ฑฐ๋ foreach๋ฅผ ์จ์ ๋ฐฐ์ด ์ ์ฒด ์ํ๋ฅผ ์ํค๋๊ฒ ์์ ์ฑ์ด ๋์
์ ํน์ i๊ฐ ์ค์ ์กด์ฌํ๋ ๋ผ์ดํธํ๋ ์ด์ค๋ค๋ณด๋ค ๋ง์์ ธ์ ์๊ธฐ๋๊ฑฐ์?
ใ ใ ๊ทธ๋ฌ๋ฉด ๋น์ฐํ ๋ฒ๊ทธ๊ฐ ํฐ์ง
Listํ์ Linq๋ก for(var i = 0; i < LighePlaces.Count; i++) ์ฐ๋ฉด ์์ ํ๊ฒ ์ธ ์ ์์์ฐ