Hello everyone.
I have a question about how to place items on a table exactly in the center of it in a fixed way, which the player can pick up or place whenever he wants. An example is as seen in the game “Overcooked”… seems like its works like a grid.
Following is the script I have made in the hurry up. You can check this. I tried to set random scale and positions and it worked. But there might be the special cases which need to consider as per the requirements
using UnityEngine;
using System.Collections;
public class TableChild : MonoBehaviour
{
MeshRenderer meshRenderer;
void Start ()
{
meshRenderer = gameObject.transform.GetComponent<MeshRenderer> ();
}
void OnCollisionEnter (Collision col)
{
MakeChild (col.gameObject);
}
private void MakeChild (GameObject go)
{
//getting externs bond
Vector3 goBonds = go.GetComponent<MeshRenderer> ().bounds.extents;
//Setting the positon of the object
go.transform.position = new Vector3 (gameObject.transform.position.x,
meshRenderer.bounds.extents.y + goBonds.y + gameObject.transform.position.y,
0);
// After setting the position then making the child
go.transform.SetParent (gameObject.transform);
go.GetComponent<Rigidbody> ().isKinematic = true;
}
}
Its works here! I made some modifications in it for my project and it worked well. Thank you so much @itsharshdeep
Its works here! I made some modifications in it for my project and it worked well. Thank you so much @itsharshdeep
– Rbrons