Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public enum State
- {
- Suge,
- CanMove,
- Falling,
- DoubleSuge,
- }
- // Use this for initialization
- void Start ()
- {
- Player1State = State.Falling;
- Player2State = State.Falling;
- hinges = new HingeJoint[2];
- hinges = GetComponents<HingeJoint>();
- hinges[0].connectedBody = empty1.rigidbody;
- hinges[1].connectedBody = empty2.rigidbody;
- }
- // Update is called once per frame
- void Update ()
- {
- // SET STATES
- if (Input.GetKey(KeyCode.S) && player1Touch)
- {
- if (Player1State != State.Suge)
- justPressedSuge1 = true;
- else
- justPressedSuge1 = false;
- if (justPressedSuge1)
- {
- // Reset cylinder rigidbody
- rigidbody.velocity = Vector3.zero;
- rigidbody.angularVelocity = Vector3.zero;
- }
- Player1State = State.Suge;
- transform.FindChild("Lys1").GetComponent<Light>().enabled = true;
- }
- else if (!Input.GetKey(KeyCode.S) && Input.GetKey(KeyCode.DownArrow))
- {
- Player1State = State.CanMove;
- transform.FindChild("Lys1").GetComponent<Light>().enabled = false;
- }
- else if (Input.GetKey(KeyCode.S) && Input.GetKey(KeyCode.DownArrow) && player1Touch && player2Touch)
- {
- Player1State = State.DoubleSuge;
- Player2State = State.DoubleSuge;
- }
- else
- {
- Player1State = State.Falling;
- transform.FindChild("Lys1").GetComponent<Light>().enabled = false;
- }
- // SWITCH ON STATES
- switch (Player1State)
- {
- case State.Suge:
- if (suckingNow1 == false)
- {
- suckTimes++;
- suckingNow1 = true;
- }
- // Swallow to world (sticky)
- hinges[0].connectedBody = null;
- // Motor force = 0
- JointMotor myForce_suge = hinges[0].motor;
- myForce_suge.force = 0;
- // Velocity = 0
- myForce_suge.targetVelocity = 0f;
- // Set all
- hinges[0].motor = myForce_suge;
- break;
- case State.CanMove:
- hinges[0].connectedBody = empty1.rigidbody;
- if (Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.D) && Player2State == State.Suge)
- {
- // LEFT
- // Motor target velocity
- // Can't directly change the property
- JointMotor myMotor = hinges[0].motor; // make new motor
- myMotor.targetVelocity = targetVelocity; // assign value
- hinges[0].motor = myMotor; // put value back in property
- // Motor force
- JointMotor myForce = hinges[0].motor;
- myForce.force = motorForce;
- hinges[0].motor = myForce;
- }
- else if (Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.A) && Player2State == State.Suge)
- {
- // RIGHT
- hinges[0].connectedBody = empty1.rigidbody;
- // Motor target velocity
- // Can't directly change the property
- JointMotor myMotor = hinges[0].motor; // make new motor
- myMotor.targetVelocity = -targetVelocity; // assign value
- hinges[0].motor = myMotor; // put value back in property
- // Motor force
- JointMotor myForce = hinges[0].motor;
- myForce.force = motorForce;
- hinges[0].motor = myForce;
- }
- else
- {
- // NOT MOVING
- // Motor force = 0
- //hinges[0].motor.force = 0; // DON'T WORK
- JointMotor myForce = hinges[0].motor;
- myForce.force = 0;
- // Velocity = 0
- myForce.targetVelocity = 0f;
- // Set all
- hinges[0].motor = myForce;
- }
- break;
- case State.Falling:
- suckingNow1 = false;
- // Connect to itself --> falls down
- hinges[0].connectedBody = empty1.rigidbody;
- // Motor force = 0
- JointMotor myForce_again = hinges[0].motor;
- myForce_again.force = 0;
- // Velocity = 0
- myForce_again.targetVelocity = 0f; // put value back in property
- // Set
- hinges[0].motor = myForce_again;
- break;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement