Ejemplo n.º 1
0
 // Update is called once per frame
 void Update()
 {
     if (socket.IsFilled())
     {
         trigger.Trigger();
         this.enabled = false;
         pluggedIn.Invoke();
     }
 }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (grabbed)
        {
            //Right mouse lets go
            if (Input.GetMouseButtonDown(1))
            {
                grabbed = false;
                Dangle(true);
            }

            //Left Mouse plugs in;
            if (Input.GetMouseButtonDown(0) && closeToSocket && InteractingSocket != null && !InteractingSocket.IsFilled())
            {
                PlugIn();
            }

            //Follow the mouse
            Vector3 newPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            newPos.z = 0;
            GetComponent <Rigidbody2D>().MovePosition(newPos);

            //Move point towards movement direction
            if (!closeToSocket && GetVelocity().magnitude > 0.02)
            {
                var   v     = GetVelocity();
                float angle = Mathf.Atan2(v.y, v.x) * Mathf.Rad2Deg;

                transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.AngleAxis(angle + 90, Vector3.forward), 20 * Time.deltaTime);
            }
        }
    }