public GameObject Miffy;
void OnTriggerEnter(Collider collider)
{
//when space key is pressed and collider is miffy(tagged Player)
if (Input.GetKey(KeyCode.P) && collider.gameObject.tag == "Player")
{
Ball.transform.parent = Miffy.transform;
Ball.transform.localPosition = new Vector3(0, 0, 0);
}
}
private void Update()
{
//when key D is pressed miffy is no longer parent to ball object.
if (Input.GetKeyDown(KeyCode.D))
{
Ball.transform.SetParent(null);
}
}
子对象(球)随着父(米菲)对象移动而增加的距离。