BT723
1
I created a script for picking up an object(cube) and whenever I do this it changes scale and I am not sure why or how to fix this.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class pickup : MonoBehaviour
{
public Transform theDest;
void OnMouseDown()
{
GetComponent<BoxCollider>().enabled = false;
GetComponent<Rigidbody>().useGravity = false;
GetComponent<Rigidbody>().freezeRotation = false;
this.transform.position = theDest.position;
this.transform.parent = GameObject.Find("Tempparent").transform;
}
void OnMouseUp()
{
this.transform.parent = null;
GetComponent<Rigidbody>().useGravity = true;
GetComponent<Rigidbody>().freezeRotation = true;
GetComponent<BoxCollider>().enabled = true;
}
}
thanks
mgear
2
maybe parent transform is scaled?
could try this, with the 2nd parameter set to true:
1 Like
BT723
3
so instead of using void onmousedown and void onmouseup I would use public void (transform newparent)?
BT723
4
I changed my script but now it doesn’t work instead the cube just flys away and has no gravity when I test it
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class pickup : MonoBehaviour
{
public Transform theDest;
public GameObject player;
void OnMouseDown(Transform Tempparent)
{
GetComponent<BoxCollider>().enabled = false;
GetComponent<Rigidbody>().useGravity = false;
GetComponent<Rigidbody>().freezeRotation = false;
this.transform.position = theDest.position;
player.transform.SetParent(Tempparent);
}
void OnMouseUp(Transform Tempparent)
{
GetComponent<Rigidbody>().useGravity = true;
GetComponent<Rigidbody>().freezeRotation = true;
GetComponent<BoxCollider>().enabled = true;
player.transform.SetParent(Tempparent, false);
}
}