I made and openable box with hinge joints. When I press E on it, it sets the hinge.limit.max from 0 to 170.
The problem is that it only affects the main object/prefab. Even when I try to open an other box that I placed with the prefab, only the main object/prefab opens.
Here is the script that I use.
#pragma strict
var testObj : GameObject;
var hinge = gameObject.GetComponent(HingeJoint);
var limits = hinge.limits;
private var canHover : boolean = false;
function Update()
{
var fwd = transform.TransformDirection(Vector3.forward);
var hit : RaycastHit;
if (Physics.Raycast(transform.position, fwd, hit))
{
if(hit.distance <= 5.0 && hit.collider.gameObject.tag == "box")
{
canHover = true;
if(Input.GetKeyDown("e"))
{
hinge.limits.max = 170;
}
}
else
{
canHover = false;
}
}
}
function OnGUI()
{
if(canHover == true)
{
GUI.Box(Rect(Screen.width / 2 - 100, Screen.height / 2 - 100, 150, 20), "Open");
}
}
↧