여러 개의 메쉬 콜리더로 구성된 구가 슬롯에 있고, 플레이어가 퍼즐 피스 (또는 메쉬 콜리더)를 구와 접촉하도록 움직이는 퍼즐 게임을하고 있습니다. 충돌 한 메쉬 콜 리더 '슬롯'에 달라 붙을 것입니다. 그러나 제 스크립트는 이상하게 작동합니다. 그것은 때로는 고착하고, 다른 때에는 게임 세계로 떠내려갑니다. 어떻게 작동시킬 수 있습니까?여러 메쉬 콜리 더를 결합하는 유니티
다음은 퍼즐 조각이에 충실 해야하는 구, 그리고 퍼즐 조각 자체의 하나
구는 자신의 메쉬 입자 가속기 각각 여러 메쉬로 구성되어있다. 왼쪽의 불규칙한 모양의 물체가 퍼즐 조각 중 하나입니다. 플레이어가 구를 향해 움직이면 구에있는 첫 번째 메쉬 콜 리더에 달라 붙어 있어야합니다.
using UnityEngine;
using System.Collections;
public class StickyObject : MonoBehaviour {
DragToMove1 otherScript;
GameObject mainObj, jigsphere;
bool stuck;
public LayerMask layerMask;
// Use this for initialization
void Start()
{
otherScript = this.GetComponent<DragToMove1>();
mainObj = GameObject.Find("GameObject");
stuck = false;
}
// Update is called once per frame
void Update()
{
if (stuck)
{
}
}
void OnCollisionEnter(Collision c)
{
if (!stuck)
{
//By contact point
ContactPoint touched = c.contacts[0];
Debug.Log ("Collision with " + this.name);
touched.otherCollider.gameObject.transform.parent = this.transform;
Debug.Log ("Parented to " + touched.otherCollider);
stuck = true;
if (otherScript != null)
{
otherScript.Stuck();
otherScript.selected = false;
}
mainObj.SendMessage ("Wake");
}
}
bool getStuck()
{
return stuck;
}
}
그게 효과가! 감사! –