/*public int countScore(){ * count=0; * for(int i=0;i<inventory.treasures.Count;i++){ * count+=inventory.treasures[i].value; * } * return count; * }*/ void forceGrab(bool pressedA) { RaycastHit outHit; numitems.text = "test"; //notice I'm using the layer mask again if (Physics.Raycast(rightPointerObject.transform.position, rightPointerObject.transform.up, out outHit, 100.0f, collectiblesMask)) { numitems.text = "hit"; AttachmentRule howToAttach = pressedA?AttachmentRule.KeepWorld:AttachmentRule.SnapToTarget; attachGameObjectToAChildGameObject(outHit.collider.gameObject, rightPointerObject.gameObject, howToAttach, howToAttach, AttachmentRule.KeepWorld, true); grabbed = outHit.collider.gameObject.GetComponent <CollectibleTreasure>(); if (grabbed.name == "CubeCollectible") { rotate = true; } else { rotate = false; } // Vector3 scaleChange = new Vector3(-0.01f, -0.01f, -0.01f); presize = grabbed.transform.localScale.y; grabbed.transform.localScale = new Vector3(2, 2, 2); // } }
// Per Nick's VRPawn public void attachGameObjectToChild(GameObject GOAttach, GameObject newParent, AttachmentRule locationRule, AttachmentRule rotationRule, AttachmentRule scaleRule, bool weld) { GOAttach.transform.parent = newParent.transform; handleAttachmentRules(GOAttach, locationRule, rotationRule, scaleRule); if (weld) { simulatePhysics(GOAttach, Vector3.zero, false); } }
//could have more easily just passed in attachment rule.... but I wanted to keep the code similar to the BP example void forceGrab(bool pressedA) { RaycastHit outHit; //notice I'm using the layer mask again if (Physics.Raycast(rightPointerObject.transform.position, rightPointerObject.transform.up, out outHit, 100.0f, collectiblesMask)) { AttachmentRule howToAttach = pressedA?AttachmentRule.KeepWorld:AttachmentRule.SnapToTarget; attachGameObjectToAChildGameObject(outHit.collider.gameObject, rightPointerObject.gameObject, howToAttach, howToAttach, AttachmentRule.KeepWorld, true); thingIGrabbed = outHit.collider.gameObject.GetComponent <Collectible>(); } }
public static void handleAttachmentRules(GameObject GOToHandle, AttachmentRule locationRule, AttachmentRule rotationRule, AttachmentRule scaleRule) { GOToHandle.transform.localPosition = (locationRule == AttachmentRule.KeepRelative)?GOToHandle.transform.position: //technically don't need to change anything but I wanted to compress into ternary (locationRule == AttachmentRule.KeepWorld)?GOToHandle.transform.localPosition: new Vector3(0, 0, 0); //localRotation in Unity is actually a Quaternion, so we need to specifically ask for Euler angles GOToHandle.transform.localEulerAngles = (rotationRule == AttachmentRule.KeepRelative)?GOToHandle.transform.eulerAngles: //technically don't need to change anything but I wanted to compress into ternary (rotationRule == AttachmentRule.KeepWorld)?GOToHandle.transform.localEulerAngles: new Vector3(0, 0, 0); GOToHandle.transform.localScale = (scaleRule == AttachmentRule.KeepRelative)?GOToHandle.transform.lossyScale: //technically don't need to change anything but I wanted to compress into ternary (scaleRule == AttachmentRule.KeepWorld)?GOToHandle.transform.localScale: new Vector3(1, 1, 1); }
public static void detachGameObject(GameObject GOToDetach, AttachmentRule locationRule, AttachmentRule rotationRule, AttachmentRule scaleRule) { //making the parent null sets its parent to the world origin (meaning relative & global transforms become the same) GOToDetach.transform.parent = null; handleAttachmentRules(GOToDetach, locationRule, rotationRule, scaleRule); }