Advertisement
Guest User

SuctionCoOp

a guest
May 31st, 2011
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.92 KB | None | 0 0
  1. public enum State
  2. {
  3.     Suge,
  4.     CanMove,
  5.     Falling,
  6.     DoubleSuge,
  7. }
  8.  
  9. // Use this for initialization
  10.     void Start ()
  11.     {
  12.         Player1State = State.Falling;
  13.         Player2State = State.Falling;
  14.  
  15.         hinges = new HingeJoint[2];
  16.         hinges = GetComponents<HingeJoint>();
  17.  
  18.         hinges[0].connectedBody = empty1.rigidbody;
  19.         hinges[1].connectedBody = empty2.rigidbody;
  20.    
  21.     }
  22.    
  23.     // Update is called once per frame
  24.     void Update ()
  25.     {
  26.         // SET STATES
  27.         if (Input.GetKey(KeyCode.S) && player1Touch)
  28.         {
  29.             if (Player1State != State.Suge)
  30.                 justPressedSuge1 = true;
  31.             else
  32.                 justPressedSuge1 = false;
  33.            
  34.             if (justPressedSuge1)
  35.             {
  36.                 // Reset cylinder rigidbody
  37.                 rigidbody.velocity = Vector3.zero;
  38.                 rigidbody.angularVelocity = Vector3.zero;
  39.             }
  40.  
  41.             Player1State = State.Suge;
  42.             transform.FindChild("Lys1").GetComponent<Light>().enabled = true;
  43.            
  44.         }
  45.         else if (!Input.GetKey(KeyCode.S) && Input.GetKey(KeyCode.DownArrow))
  46.         {
  47.             Player1State = State.CanMove;
  48.             transform.FindChild("Lys1").GetComponent<Light>().enabled = false;
  49.         }
  50.         else if (Input.GetKey(KeyCode.S) && Input.GetKey(KeyCode.DownArrow) && player1Touch && player2Touch)
  51.         {
  52.             Player1State = State.DoubleSuge;
  53.             Player2State = State.DoubleSuge;
  54.         }
  55.  
  56.         else
  57.         {
  58.             Player1State = State.Falling;
  59.             transform.FindChild("Lys1").GetComponent<Light>().enabled = false;
  60.         }
  61.  
  62.         // SWITCH ON STATES
  63.         switch (Player1State)
  64.         {
  65.             case State.Suge:
  66.                
  67.                 if (suckingNow1 == false)
  68.                 {
  69.                     suckTimes++;
  70.                     suckingNow1 = true;
  71.                 }
  72.                 // Swallow to world (sticky)
  73.                 hinges[0].connectedBody = null;
  74.  
  75.                 // Motor force = 0
  76.                 JointMotor myForce_suge = hinges[0].motor;
  77.                 myForce_suge.force = 0;
  78.  
  79.                 // Velocity = 0
  80.                 myForce_suge.targetVelocity = 0f;
  81.                
  82.                
  83.                 // Set all
  84.                 hinges[0].motor = myForce_suge;
  85.  
  86.  
  87.                 break;
  88.  
  89.             case State.CanMove:
  90.                 hinges[0].connectedBody = empty1.rigidbody;
  91.  
  92.                 if (Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.D) && Player2State == State.Suge)
  93.                 {
  94.                     // LEFT
  95.                     // Motor target velocity
  96.                     // Can't directly change the property
  97.                     JointMotor myMotor = hinges[0].motor; // make new motor
  98.                     myMotor.targetVelocity = targetVelocity; // assign value
  99.                     hinges[0].motor = myMotor; // put value back in property
  100.  
  101.                     // Motor force
  102.                     JointMotor myForce = hinges[0].motor;
  103.                     myForce.force = motorForce;
  104.                     hinges[0].motor = myForce;
  105.                 }
  106.                 else if (Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.A) && Player2State == State.Suge)
  107.                 {
  108.                     // RIGHT
  109.  
  110.                     hinges[0].connectedBody = empty1.rigidbody;
  111.  
  112.                     // Motor target velocity
  113.                     // Can't directly change the property
  114.                     JointMotor myMotor = hinges[0].motor; // make new motor
  115.                     myMotor.targetVelocity = -targetVelocity; // assign value
  116.                     hinges[0].motor = myMotor; // put value back in property
  117.  
  118.                     // Motor force
  119.                     JointMotor myForce = hinges[0].motor;
  120.                     myForce.force = motorForce;
  121.                     hinges[0].motor = myForce;
  122.                 }
  123.                 else
  124.                 {
  125.                     // NOT MOVING
  126.  
  127.                     // Motor force = 0
  128.                     //hinges[0].motor.force = 0; // DON'T WORK
  129.                     JointMotor myForce = hinges[0].motor;
  130.                     myForce.force = 0;
  131.  
  132.                     // Velocity = 0
  133.                     myForce.targetVelocity = 0f;
  134.  
  135.                     // Set all
  136.                     hinges[0].motor = myForce;                
  137.  
  138.                 }
  139.                 break;
  140.  
  141.             case State.Falling:
  142.                    
  143.                 suckingNow1 = false;
  144.            
  145.                 // Connect to itself --> falls down
  146.                 hinges[0].connectedBody = empty1.rigidbody;
  147.  
  148.  
  149.                 // Motor force = 0
  150.                 JointMotor myForce_again = hinges[0].motor;
  151.                 myForce_again.force = 0;
  152.                
  153.                 // Velocity = 0
  154.                 myForce_again.targetVelocity = 0f; // put value back in property
  155.  
  156.                 // Set
  157.                 hinges[0].motor = myForce_again;
  158.  
  159.                 break;
  160.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement