public void SetupModeUpdate( ) { if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger)) { if (Physics.Raycast(transform.position, transform.forward, out hit)) { var shelfTankObject = hit.collider.GetComponent<ShelfTank>(); var tank = hit.collider.GetComponent<Tank>(); if (shelfTankObject != null) { DestroyCarriedObject(); var carriedObject = GameObject.Instantiate(shelfTankObject.SelectionPrefab, shelfTankObject.transform.position, shelfTankObject.transform.rotation) as GameObject; var selectionObject = carriedObject.GetComponent<SelectionTank>(); selectionObject.Attach = transform; var direction = Vector3.forward; var distance = Vector3.Distance(transform.position, selectionObject.transform.position); CarriedSelectionTank = selectionObject; PrefabToSpawn = shelfTankObject.SpawningPrefab; } else if (tank != null) { DestroyCarriedObject(); DropCarriedTank(); tank.PickUp(this); CarriedTank = tank; } } } else if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger)) { if (CarriedSelectionTank != null) { var spawnedTank = GameObject.Instantiate(PrefabToSpawn, CarriedSelectionTank.transform.position, CarriedSelectionTank.transform.rotation) as GameObject; spawnedTank.GetComponent<Rigidbody>().velocity = new Vector3(); } if (CarriedTank != null) { DropCarriedTank(); } DestroyCarriedObject(); } }
public void DestroyCarriedObject() { if (CarriedSelectionTank != null) { GameObject.Destroy(CarriedSelectionTank.gameObject); CarriedSelectionTank = null; PrefabToSpawn = null; } }