Question by
MichaelABC · Oct 28, 2021 at 01:30 PM ·
collisioninstantiateraycast
Instantiate object only once
Int_Molecule should instantiate only once, but if it touches more than one corner (UR = UP RIGHT, UL = UP LEFT, etc.) it instantiated twice. Is there a way to instantiate the object only once?
To give you a more complete picture: External molecules have detectors that detect collision, while internal ones have holders to hold the newly instantiated molecules.
private void UR_Attach()
{
RaycastHit2D Ext2Int = Physics2D.Raycast(UR_Detector.position, Vector2.zero, -0);
if (Ext2Int.collider != null && Ext2Int.collider.tag == "Ext_Molecule")
{
Ext2Int.collider.gameObject.tag = "Untagged";
Destroy(Ext2Int.collider.gameObject);
Transform Int_Molecule_Inst = Instantiate(this.Int_MoleculePrefab);
Int_Molecule_Inst.transform.parent = UR_Holder;
Int_Molecule_Inst.transform.position = UR_Holder.position;
}
organ2.gif
(392.5 kB)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613044723im_/https://answers.unity.com/themes/thub/images/avi.jpg)