Game Development Reference
In-Depth Information
Listing 6.6 Setting Transform Positions for Multiple
Picked-up Objects
var attachPoint: GameObject;
private var currentObj: GameObject;
function Start()
{
//first held object
currentObj = GameObject.Find("wrench");
}
function OnControllerColliderHit (hit :
ControllerColliderHit)
{
if(hit.gameObject.tag == "key")
{
Destroy(hit.gameObject.collider);
hit.gameObject.transform.parent = attachPoint.
transform;
if(hit.gameObject.name == "wrench")
{
hit.gameObject.transform.localPosition =
Vector3(—0.001,0.0003,0.0005);
hit.gameObject.transform.localScale =
Vector3(1,1,1);
hit.transform.localEulerAngles =
Vector3(13.6,332,319.1);
}
else
{
hit.gameObject.transform.localPosition =
Vector3( - 0.0009,0.0001,0.0002);
hit.gameObject.transform.localScale =
Vector3(0.005,0.005,0.005);
hit.transform.localEulerAngles =
Vector3(299,286,312);
}
//release the previously held game object
currentObj.transform.parent = null;
currentObj.AddComponent(BoxCollider);
//set currentObj to the new object — just picked up
currentObj = hit.gameObject;
}
}
Search Nedrilad ::




Custom Search