You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.0 KiB

  1. using UnityEngine;
  2. using System.Collections;
  3. public class liftScale : MonoBehaviour {
  4. public GameObject otherObject;
  5. public liftScale otherScript;
  6. private Rigidbody rigidbody;
  7. private float minHeight;
  8. private float maxHeight;
  9. private float startingHeight;
  10. private float otherStartingHeight;
  11. private Vector3 prevPosition;
  12. private Vector3 otherPrevPosition;
  13. private int top = 1;
  14. // Use this for initialization
  15. void Start () {
  16. rigidbody = GetComponent <Rigidbody> ();
  17. maxHeight = Mathf.Max (transform.position.y, otherObject.transform.position.y);
  18. minHeight = Mathf.Min (transform.position.y, otherObject.transform.position.y);
  19. startingHeight = transform.position.y;
  20. otherStartingHeight = otherObject.transform.position.y;
  21. if (startingHeight < otherStartingHeight){
  22. top = -1;
  23. }
  24. }
  25. // Update is called once per frame
  26. void Update () {
  27. if (transform.position != prevPosition) {
  28. float dist = Mathf.Abs(startingHeight - transform.position.y);
  29. prevPosition = transform.position;
  30. Vector3 newPos = otherObject.transform.position;
  31. newPos.y = otherStartingHeight + (dist * top);
  32. //otherObject.transform.position = newPos;
  33. otherObject.GetComponent<Rigidbody>().MovePosition(newPos);
  34. //otherObject.GetComponent<Rigidbody>().velocity = -GetComponent<Rigidbody>().velocity;
  35. otherScript.prevPosition = otherObject.transform.position;
  36. }
  37. rigidbody.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionZ;
  38. /*
  39. if (otherObject.transform.position != otherPrevPosition) {
  40. float dist = Mathf.Abs(otherStartingHeight - otherObject.transform.position.y);
  41. Vector3 newPos = transform.position;
  42. newPos.y = startingHeight + (dist * -top);
  43. transform.position = newPos;
  44. prevPosition = transform.position;
  45. }*/
  46. }
  47. /*
  48. void OnTriggerStay(Collider collider) {
  49. if (collider.transform.tag == "Player") {
  50. Vector3 pos = collider.transform.position;
  51. pos.y = transform.position.y;
  52. collider.transform.position = pos;
  53. }
  54. }
  55. */
  56. }