Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

VR Tradeshow

Discussion in 'Scripting' started by Dark3D, Aug 30, 2008.

  1. Dark3D

    Dark3D

    Joined:
    Aug 30, 2008
    Posts:
    53
    Hi, Just wanted to share some code and ask if anyone would like to help us to improve. We would like to start another vehicle the forklift but I cant do both at the same time.... To enter E key exit Q key.



    Code (csharp):
    1.  
    2. ;(
    3.  
    4.  
    5.  
    6. // this is attched to the Player
    7.  
    8.  
    9. var cam : GameObject; // Player
    10. var SpringCamCart : GameObject; //GolfCart is the controller
    11. var cam3: GameObject; // GolfCart Cam
    12.  
    13. cam3.camera.enabled = false;
    14. SpringCamCart.active = false;
    15.  
    16.  
    17. function OnTriggerEnter (other : Collider) {
    18.  
    19.  
    20. if (Input.GetKeyDown (KeyCode.E)){
    21. cam.camera.enabled = false;
    22. SpringCamCart.active = true;
    23. cam3.camera.enabled = true;
    24. }
    25.  
    26.  
    27. if (Input.GetKeyDown (KeyCode.Q)) {
    28. cam.camera.enabled = true;
    29. SpringCamCart.active = false;
    30. }
    31.  
    32. }
    33.  
    34.  
    35.  
    36. script 2
    37. // this is attched to the GolfCart
    38.  
    39.  
    40.  
    41. var cam : GameObject; // Player
    42. var cam3 : GameObject;// GolfCart Cam
    43. var SpringCamCart : GameObject; // is the controller
    44.  
    45.  
    46.  
    47.  
    48.  
    49.  
    50.  
    51. function OnTriggerEnter (other : Collider)  {  
    52.    
    53.  
    54.    
    55.    
    56. if (Input.GetKeyDown (KeyCode.Q)) {
    57. print ("Q key was pressed");
    58. SpringCamCart.active = false;
    59. cam.camera.enabled = true;
    60. cam3.camera.enabled = false;
    61.  
    62. }
    63.  
    64. }
    65.  
    66. function OnCollisionEnter(collision : Collision) {
    67.     if (collision.relativeVelocity.magnitude > 2){
    68. print ("sound playing");
    69. //audio.Play();
    70. }
    71.  
    72. }
    73.  
    Sample of VR Tradeshow:
    http://www.interactivemagicworks.com/VRTradeshow.php
     
  2. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    I'm sorry but after a quick look I'm not sure I understand your question, can you clarify what you're hoping to achieve a bit more? It sounds like you want to be able to have some code so that you can walk up to either the forklift or the golf cart, press E and begin driving that vehicle, then when done press Q to exit that vehicle. Is that correct?
     
  3. Dark3D

    Dark3D

    Joined:
    Aug 30, 2008
    Posts:
    53

    Thanks Higgy, I think I will will just assign a different key for each object, like C for cart and F for forklift. But... I was originally thinking of making a trigger know what specific object you were next to, they pop up a menu for that item, which could be useful for allot of applications.

    Thanks.