Hello, as I am just starting to learn how to use unity, I am making a project to test unity which consists of a stickman that you can click and drag around the screen by the head. The problem is, the script I have on the head seems to cause the entire stickman to disappear when I click on it. I have the head as the parent of the torso and all limbs so that they move together, if that’s important. I followed a tutorial to make this, but they didn’t have the same problem in the video. Here is all of my code:
private float startPosX;
private float startPosY;
private bool isBeingHeld = false;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (isBeingHeld == true)
{
Vector3 mousePos;
mousePos = Input.mousePosition;
mousePos = Camera.main.ScreenToWorldPoint(mousePos);
this.gameObject.transform.localPosition = new Vector3(mousePos.x, mousePos.y, 0);
}
}
private void OnMouseDown()
{
if (Input.GetMouseButtonDown(0))
{
isBeingHeld = true;
}
}
private void OnMouseUp()
{
isBeingHeld = false;
}