Question by
MichaelABC · Oct 16, 2021 at 12:41 PM ·
transform.positionvector2
How to add a particular distance to transform.position
I would like to move the "molecule" object to UR_Detector.position += new Vector(0.4,0.4) but the syntax is not logically correct.
Any suggestion?
private void UR_Attach()
{
RaycastHit2D attachCheck = Physics2D.Raycast(UR_Detector.position, Vector2.one * transform.localScale, 0);
if (attachCheck.collider != null && attachCheck.collider.tag == "Molecule")
{
attachCheck.collider.gameObject.transform.parent = UR_Detector;
attachCheck.collider.gameObject.transform.position = UR_Detector.position += new Vector2 (0.4,0.4);
if (Input.GetKey(KeyCode.X))
{
attachCheck.collider.gameObject.transform.parent = null;
}
}
}
Comment
Answer by MichaelABC · Oct 17, 2021 at 12:02 PM
I solved by adding a new viarable to store the location of the molecule, however this is not as lean as I hoped it was