Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

enter able boat script need help

Discussion in 'Scripting' started by Darkdragon0011, Jun 2, 2016.

  1. Darkdragon0011

    Darkdragon0011

    Joined:
    Apr 27, 2015
    Posts:
    35
    Hi guys, i am trying to make a game where i can enter a boat and exit, how would i go about doing that thanks!!

    (P.S if you do have a script i could use it would be much appreciated!)
     
  2. Darkdragon0011

    Darkdragon0011

    Joined:
    Apr 27, 2015
    Posts:
    35
    Code (CSharp):
    1. // js adaptation by WarpZone
    2.  
    3. // Put this on a rigidbody object and instantly
    4. // have 2D spaceship controls like OverWhelmed Arena
    5. // that you can tweak to your heart's content.
    6.  
    7. @script RequireComponent (Rigidbody)
    8.  
    9.     var hoverHeight : float = 120;
    10.     var hoverHeightStrictness : float = 1.0;
    11.     var  forwardThrust : float = 5000.0;
    12.     var  backwardThrust : float = 2500.0;
    13.     var  bankAmount : float = 0.1;
    14.     var  bankSpeed : float = 0.2;
    15.     var  bankAxis : Vector3 = new Vector3(-1.0, 0.0, 0.0);
    16.     var  turnSpeed : float = 8000.0;
    17.    
    18.     var  forwardDirection : Vector3 = new Vector3(0.0, 0.0, 1.0);
    19.  
    20.     var  mass : float = 5.0;
    21.    
    22.     // positional drag
    23.     var sqrdSpeedThresholdForDrag : float = 25.0;
    24.     var superDrag : float = 2.0;
    25.     var fastDrag : float = 0.5;
    26.     var slowDrag : float = 0.01;
    27.    
    28.     // angular drag
    29.     var sqrdAngularSpeedThresholdForDrag : float = 5.0;
    30.     var superADrag : float = 32.0;
    31.     var fastADrag : float = 16.0;
    32.     var slowADrag : float = 0.1;
    33.    
    34.  
    35.    
    36.     var playerControl : boolean = true;
    37.    
    38.     private var bank : float = 0.0;
    39.  
    40.     function SetPlayerControl(control : boolean)
    41.     {
    42.         playerControl = control;
    43.     }
    44.  
    45.  
    46.     function Start()
    47.     {
    48.         gameObject.GetComponent.<Rigidbody>().mass = mass;
    49.     }
    50.    
    51.     function FixedUpdate()
    52.     {
    53.         if (Mathf.Abs(thrust) > 0.01)
    54.         {
    55.             if (GetComponent.<Rigidbody>().velocity.sqrMagnitude > sqrdSpeedThresholdForDrag)
    56.                 GetComponent.<Rigidbody>().drag = fastDrag;
    57.             else
    58.                 GetComponent.<Rigidbody>().drag = slowDrag;
    59.         }
    60.         else
    61.             GetComponent.<Rigidbody>().drag = superDrag;
    62.                    
    63.         if (Mathf.Abs(turn) > 0.01)
    64.         {
    65.             if (GetComponent.<Rigidbody>().angularVelocity.sqrMagnitude > sqrdAngularSpeedThresholdForDrag)
    66.                 GetComponent.<Rigidbody>().angularDrag = fastADrag;
    67.             else
    68.                 GetComponent.<Rigidbody>().angularDrag = slowADrag;
    69.         }
    70.         else
    71.             GetComponent.<Rigidbody>().angularDrag = superADrag;
    72.        
    73.         transform.position = Vector3.Lerp(transform.position, new Vector3(transform.position.x, hoverHeight, transform.position.z), hoverHeightStrictness);
    74.        
    75.         var amountToBank : float = GetComponent.<Rigidbody>().angularVelocity.y * bankAmount;
    76.  
    77.         bank = Mathf.Lerp(bank, amountToBank, bankSpeed);
    78.        
    79.         var rotation : Vector3 = transform.rotation.eulerAngles;
    80.         rotation *= Mathf.Deg2Rad;
    81.         rotation.x = 0;
    82.         rotation.z = 0;
    83.         rotation += bankAxis * bank;
    84.         rotation *= Mathf.Rad2Deg;
    85.         transform.rotation = Quaternion.Euler(rotation);
    86.     }
    87.    
    88.     // thrust
    89.     private var thrust : float = 0;
    90.     private var turn : float = 0;
    91.    
    92.     function Thrust( t : float )
    93.     {
    94.         thrust = Mathf.Clamp( t, -1.0, 1.0 );
    95.     }
    96.    
    97.     function Turn(t : float)
    98.     {
    99.         turn = Mathf.Clamp( t, -1.0, 1.0 ) * turnSpeed;
    100.     }
    101.    
    102.     private var thrustGlowOn : boolean = false;
    103.    
    104.     function Update ()
    105.     {
    106.         var theThrust : float = thrust;
    107.        
    108.         if (playerControl)
    109.         {
    110.             thrust = Input.GetAxis("Vertical");
    111.             turn = Input.GetAxis("Horizontal") * turnSpeed;
    112.         }
    113.                
    114.         if (thrust > 0.0)
    115.         {
    116.             theThrust *= forwardThrust;
    117.             if (!thrustGlowOn)
    118.             {
    119.                 thrustGlowOn = !thrustGlowOn;
    120.                 BroadcastMessage("SetThrustGlow", thrustGlowOn, SendMessageOptions.DontRequireReceiver);
    121.             }
    122.         }
    123.         else
    124.         {
    125.             theThrust *= backwardThrust;
    126.             if (thrustGlowOn)
    127.             {
    128.                 thrustGlowOn = !thrustGlowOn;
    129.                 BroadcastMessage("SetThrustGlow", thrustGlowOn, SendMessageOptions.DontRequireReceiver);
    130.             }
    131.         }
    132.        
    133.         GetComponent.<Rigidbody>().AddRelativeTorque(Vector3.up * turn * Time.deltaTime);
    134.         GetComponent.<Rigidbody>().AddRelativeForce(forwardDirection * theThrust * Time.deltaTime);
    135. }
    Code (CSharp):
    1. //ïî ñîáûòèþ òðèãåð ïðîèñõîäÿùåìó íà ìàøèíå îáúÿâëÿåì ãëîáàëüíóþ ïåðåìåííóþ
    2. // ñîìåð è ïðèäàåì ìàøèíå òàã ÌÌÌ ýòî äëÿ ñëó÷àÿ ðàçìíîæåíèÿ ìàøèí îá÷íûì êëîíèðîâàíèåì
    3.  
    4. var btarget : Transform;
    5.  
    6.  
    7. function OnTriggerEnter (other : Collider) {
    8.  
    9. //var bbc : Transform;
    10. //name = "Racer Car1";
    11.  
    12. btarget.position = transform.position;
    13.  
    14. somer=2;
    15.     gameObject.tag = "Player";
    16.    
    17. }      
    18.  
    19.  
    20. function OnTriggerExit (other : Collider) {
    21.  
    22.  
    23. if (gameObject.tag == "MMM")
    24.    gameObject.tag = "MMM";
    25.  
    26.  
    27.   if (gameObject.tag == "Player")
    28.    gameObject.tag = "Respawn";
    29.  
    30.     somer=0;
    31.    
    32. }      
    33.  
    34.  
    35. function Update () {
    36.  
    37.     GetComponent.<Rigidbody>().drag = 0;
    38. //ìàøèíà çàïóñêàåòñÿ ïðè íàæàòèè enter. äëÿ ýòîãî ñîáëþäàþòñÿ 2 óñëîâèÿ íàæàòèå ìûøêè
    39. // è íàõîæäåííèè ÷åëîâåêà â îáëàñòè òðèãåðà . îá ýòîì ïåðåìåííàÿ ñîìåð.
    40. //ïðè ýòîì óñëîâèè âêëþ÷àåì ñêðèïò ïëååð êàð ðàíåå îòêëþ÷åíûé â èíñïåêòîðå
    41. //è ïðè óñëîâèè ÷òî âêëþ÷åí îáúåêò ñ òàãîì ÌÌÌ
    42.  
    43. //btarget.position = transform.position + Vector3(10,10,10);
    44. //btarget = Vector3(100,100,100);
    45.  
    46.      if (gameObject.tag== "Player"){
    47.  
    48.              //ïðè íàæàòèè åíòåð
    49.  
    50.            if (Input.GetKeyDown ("return")&& (somer==2)&& GetComponent (BoatScript)){
    51.                          
    52.                          
    53.                           gameObject.tag = "MMM";
    54.                          
    55.                          
    56.                           // âêëþ÷àåì ñêðèïò  êàð ðàíåå îòêëþ÷åíûé â èíñïåêòîðå
    57.                             GetComponent (BoatScript).enabled=true ;
    58.                          
    59.                          
    60.                          
    61.                      //îòêëþ÷àåì êîíòðîëåð ó ÷åëîâåêà
    62.      
    63.                           var go = GameObject.Find("First1");
    64.                           go.GetComponent(FPSInputController).enabled = false;    
    65.                
    66.                    // îòêëþ÷àåì êàìåðó ó ÷åëîâåêà
    67.                               var go1 = GameObject.Find("Camera1");
    68.                               go1.GetComponent(Camera).enabled = false;
    69.        
    70.                  }
    71.  
    72.     }
    73.  
    74.  
    75.             if (Input.GetKeyDown ("space") &&(gameObject.tag== "MMM")){
    76.    
    77.    
    78.                     // ïåðåìåùàåì  
    79.                          var go21 = GameObject.Find("First1");
    80.    
    81.                         go21.transform.position=transform.position + Vector3(6,2,0);
    82.            
    83.                     // îòêëþ÷àåì  ñêðèïò  êàð      
    84.                           GetComponent (BoatScript).enabled=false ;  
    85.            
    86.                        
    87.                                      var go221 = GameObject.Find("Camera1");
    88.                                      go221.GetComponent(Camera).enabled = true;
    89.                                    
    90.                                    
    91.                                    
    92.                                 //     btarget.position=transform.position + Vector3(0.1,0,0);
    93.                                    
    94.                                     GetComponent.<Rigidbody>().drag = GetComponent.<Rigidbody>().velocity.magnitude / 00;
    95.  
    96.         //    name = "Racer Car";
    97.                    somer=0;  
    98.                   gameObject.tag = "Finish";
    99.             }        
    100.  
    101.  
    102.      
    103. }
    I was trying to use these how do I??