Hey,
I have figured out picking up the box and moving it around however I still need a good way to detect if I am looking at the box. right now I have a trigger added to my camera and I am using
Function OnTriggerStay()
however it is not always detecting when the trigger is in a box
here is the script that I am using to interact with the boxes
function Update(){
if(Input.GetKeyDown(KeyCode.F)){
boxaction = true;
}else if(Input.GetKeyUp(KeyCode.F)){
boxaction = false;
}
}
function OnTriggerStay(other : Collider){
Debug.Log("collider is in box");
Debug.Log(other.tag);
Debug.Log(this.tag);
var clone : GameObject;
cube = other.collider.gameObject;
if (other.collider.tag == "Cube" && boxaction && cubehold == false){
cubehold = true;
clone = Instantiate(cube, cube.transform.position, cube.transform.rotation);
Destroy(cube);
clone.transform.parent = Camera.main.transform;
clone.rigidbody.isKinematic = true;
}else if(other.collider.tag == "Cube" && boxaction == false){
cubehold = false;
other.transform.parent = null;
other.rigidbody.isKinematic = false;
}
}
Why is the trigger attached to the camera not always detecting the box?
Also I am having problems that when I pick my boxes up the mesh tends to deform, does anyone know why this is and how I can stop it?
Any help would be appreciated. Thanks