Hello there, I’m making a Box pick up script and I’m having some issues with making the box collide with stuff. ( Screen capture - 21ddc772244ee938765d08a677df9c93 - Gyazo ) I want it to collide with the walls and other boxes. my code:
using System.Collections;
using System.Collections.Generic;
using System.Data;
using UnityEditor.Timeline;
using UnityEngine;
public class BoxScript : MonoBehaviour
{
public Transform Box;
public Transform Player;
public Transform BoxPosition;
public Transform Map;
public bool isHolding = false;
public int maxDist = 5;
private void OnMouseOver()
{
if (Input.GetMouseButtonDown(0))
{
if (isHolding == false)
{
if (Vector3.Distance(Player.transform.position, Box.transform.position) < maxDist)
{
isHolding = true;
Debug.Log("Grab");
Box.GetComponent<Rigidbody>().isKinematic = true;
Box.position = BoxPosition.position;
Box.parent = BoxPosition;
}
}
}
}
private void Update()
{
if (isHolding == true)
{
if (Input.GetMouseButtonUp(0))
{
isHolding = false;
Debug.Log("Drop");
Box.GetComponent<Rigidbody>().isKinematic = false;
Box.parent = Map;
}
}
}
}