Exemple #1
0
    public void Update()
    {
        switch (state)
        {
        case DragingStatus.draging:
        {
            //if(transform.position != cursorPosition)
            //let the bottle to chase the cursor
            //{
            Vector3 cursorPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
            cursorPosition      = Camera.main.ScreenToWorldPoint(cursorPoint) + offset;
            transform.position += (cursorPosition - transform.position) / 10;
            //transform.position = Vector3.MoveTowards(transform.position, cursorPosition, 0.1f);
            //}
            break;
        }

        case DragingStatus.returning:
        {
            transform.position = Vector3.MoveTowards(transform.position, originalPosition, 0.3f);
            //set the Potion back when it's closer enough to original position
            if (Vector3.Distance(transform.position, originalPosition) <= 0.5f)
            {
                transform.position = originalPosition;
                transform.rotation = originalRotation;
                GetComponent <Rigidbody>().useGravity     = originalGravity;
                GetComponent <Rigidbody>().velocity       = Vector3.zero;
                GetComponent <Rigidbody>().freezeRotation = true;                        //Stop!
                state = DragingStatus.idle;
            }
            break;
        }
        }
    }
Exemple #2
0
 public void Start()
 {
     state            = DragingStatus.idle;
     originalPosition = transform.position;
     originalRotation = transform.rotation;
     originalGravity  = GetComponent <Rigidbody>().useGravity;
 }
Exemple #3
0
 void OnMouseDown()
 {
     //begin to drad, remove gravity
     if (state == DragingStatus.idle)
     {
         state = DragingStatus.draging;
         GetComponent <Rigidbody>().useGravity     = false;
         GetComponent <Rigidbody>().freezeRotation = false;
         //calculate the offset
         screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
         offset      = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
         //set initial position of cursor
         Vector3 cursorPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
         cursorPosition = Camera.main.ScreenToWorldPoint(cursorPoint) + offset;
     }
 }
Exemple #4
0
 public void ReturnBack()
 {
     state = DragingStatus.returning;
 }
Exemple #5
0
 public void CheckBack()
 {
     state = DragingStatus.checking;
     Invoke("ReturnBack", 0.1f);
 }