Unity/물리 맨텀 2020. 1. 23. 00:42
유니티 Scripting API https://docs.unity3d.com/ScriptReference/Physics.OverlapBox.html Collider[] OverlapBox ( Vector3 center, Vector3 halfExtents, Quaternion orientation = Quaternion.identity, int layerMask = AllLayers, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal ); center Center of the box. halfExtents Half of the size of the box in each dimension. orientati..
Unity/물리 맨텀 2019. 9. 5. 00:33
#. 문제점은? 유니티의 OnTriggerEnter는 트리거 안에 다른 콜리더가 들어 올 경우에 작동하는 함수이다. 때문에 게임에서 투사체 등에 많이 사용된다. 그런데 문제는 이러한 투사체를 스폰하는 순간에 오브젝트가 이미 트리거의 범위 안에 들어가 있다면 OnTriggerEnter가 발동하지 않는다는 문제점이 있다. 그러면서 트리거나 오브젝트를 껐다가 다시 켜는 경우에는 제대로 작동한다. #. 해결책 스폰 첫 프레임에서는 트리거의 enable = false 를 해주고, 다음 프레임에서 다시 트리거의 enable = true 를 해주면 정상 작동한다! protected override void Start() { base.Start(); StartCoroutine(ActiveCollider()); } IE..
Unity/물리 맨텀 2019. 5. 25. 23:14
Raycase를 사용할 때는 ray를 밖에서 선언하고 사용하는 방법과 별도로 선언하고 넘기는 방법이 있다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 public void Update() { float l_rayDistance = 2f; // ray를 밖에서 선언하는 방법 Ray ray = new Ray(transform.position, transform.forward); if (Physics.Raycast(ray, out RaycastHit hit, l_rayDistance)) { } // ray를 별도로 선언하지 않고 넘기는 방법 if (Physics.Raycast(transform.position, transform.forward, out RaycastHit l_h..
Unity/물리 맨텀 2018. 11. 4. 20:26
출처 : https://forum.unity.com/threads/create-ui-health-markers-like-in-world-of-tanks.432935/#post-2800360 12345678910111213141516171819202122232425262728293031using System.Collections;using System.Collections.Generic;using UnityEngine; public class WorldToScreenPoint : MonoBehaviour { public Transform target; public float yOffset = 1.5f; public RectTransform canvasRect; // 메인 캔버스 public RectTran..