|
|
- using UnityEngine;
- using System.Collections;
-
- public class liftScale : MonoBehaviour {
-
- public GameObject otherObject;
- public liftScale otherScript;
-
- private Rigidbody rigidbody;
-
- private float minHeight;
- private float maxHeight;
- private float startingHeight;
- private float otherStartingHeight;
-
-
- private Vector3 prevPosition;
- private Vector3 otherPrevPosition;
- private int top = 1;
-
- // Use this for initialization
- void Start () {
- rigidbody = GetComponent <Rigidbody> ();
- maxHeight = Mathf.Max (transform.position.y, otherObject.transform.position.y);
- minHeight = Mathf.Min (transform.position.y, otherObject.transform.position.y);
-
- startingHeight = transform.position.y;
- otherStartingHeight = otherObject.transform.position.y;
-
- if (startingHeight < otherStartingHeight){
- top = -1;
- }
-
- }
-
- // Update is called once per frame
- void Update () {
-
- if (transform.position != prevPosition) {
- float dist = Mathf.Abs(startingHeight - transform.position.y);
- prevPosition = transform.position;
-
- Vector3 newPos = otherObject.transform.position;
- newPos.y = otherStartingHeight + (dist * top);
- //otherObject.transform.position = newPos;
- otherObject.GetComponent<Rigidbody>().MovePosition(newPos);
-
- //otherObject.GetComponent<Rigidbody>().velocity = -GetComponent<Rigidbody>().velocity;
- otherScript.prevPosition = otherObject.transform.position;
- }
-
- rigidbody.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionZ;
- /*
- if (otherObject.transform.position != otherPrevPosition) {
- float dist = Mathf.Abs(otherStartingHeight - otherObject.transform.position.y);
-
- Vector3 newPos = transform.position;
- newPos.y = startingHeight + (dist * -top);
- transform.position = newPos;
- prevPosition = transform.position;
- }*/
-
-
-
-
-
-
- }
- /*
- void OnTriggerStay(Collider collider) {
- if (collider.transform.tag == "Player") {
- Vector3 pos = collider.transform.position;
- pos.y = transform.position.y;
- collider.transform.position = pos;
- }
- }
- */
- }
|