// Moves this object left and all objects to its left left, until one of them // can't move without breaking the diagram. // Returns amount actually moved, which may be less than amount asked for. public override float PushLeft(float amount) { if (LeftObject != null) { amount = LeftObject.PushLeft(amount); } else if (LeftObjectAlien != null) { if (LeftObjectAlien is MiniTreeIndividual) { // Push left until hit alien object float distance = Left - ((MiniTreeIndividual)LeftObjectAlien).Right; if (distance < amount) { amount = distance; } } } if (amount <= 0f) { // Nothing to do return(amount); } // Individuals are free to move unless anchored by an attached group. fX -= amount; return(amount); }
public void OnSceneLoaded(Scene scene, LoadSceneMode mode) { Debug.Log("Loading..."); CamRig = GameObject.Find("[CameraRig]"); CamRig.layer = LayerMask.NameToLayer("Player"); Rigidbody rb = CamRig.AddComponent <Rigidbody>(); rb.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionY; CapsuleCollider c = CamRig.AddComponent <CapsuleCollider>(); c.center = new Vector3(0, 1, 0); c.radius = .1f; c.height = 2; SteamVR_ControllerManager ControllerManager = CamRig.GetComponent <SteamVR_ControllerManager>(); LeftObject = ControllerManager.left; RightObject = ControllerManager.right; GameController = FindObjectOfType <GameController>(); leftTrackedObject = LeftObject.GetComponent <SteamVR_TrackedObject>(); rightTrackedObject = RightObject.GetComponent <SteamVR_TrackedObject>(); Turnables = new List <ITurnable>(); foreach (GameObject go in FindObjectsOfType <GameObject>()) { if (go.GetComponent <ITurnable>() != null) { Debug.Log("Adding " + go.name + " to list of turnables"); Turnables.Add(go.GetComponent <ITurnable>()); } } Debug.Log("Loaded!"); }
// Moves this object right and all objects to its left right, until one of them // can't move without breaking the diagram. // Returns amount actually moved, which may be less than amount asked for. public override float PullRight(float amount) { if (LeftObject != null) { if (LeftObject is MiniTreeGroup) { // Groups are stretchy so we can ignore if they // get stuck( and hence reduce 'amount') LeftObject.PullRight(amount); } else { amount = LeftObject.PullRight(amount); } } if (amount <= 0f) { // Nothing to do return(amount); } // Individuals are free to move unless anchored by an attached group. fX += amount; return(amount); }