Esempio n. 1
0
 public void SetAny()
 {
     verticalLookMode   = (VerticalLookMode)Options.controllerLookMode;
     mouseLookMode      = (MouseLookMode)Options.mouseLookMode;
     device             = null;
     controllerBindings = Options.controllerBindings;
     allowMouse         = true;
 }
Esempio n. 2
0
 public void SetDevice(InputDevice inputDevice)
 {
     verticalLookMode   = (VerticalLookMode)Options.controllerLookMode;
     mouseLookMode      = (MouseLookMode)Options.mouseLookMode;
     device             = inputDevice;
     controllerBindings = Options.CreateInput(inputDevice);
     allowMouse         = false;
 }
Esempio n. 3
0
    void LookToMouse()
    {
        MouseLookMode lookMode = GetLookMode();

        if (lookMode == MouseLookMode.MOUSE_TO_AIM)
        {
            // Cast a ray from screen point
            Ray ray = mouseRay;
            // Save the info
            RaycastHit hit;
            // You successfully hi
            if (Physics.Raycast(ray, out hit))
            {
                // Find the direction to move in
                Vector3 dir = hit.point - transform.position;

                // Make it so that its only in x and y axis
                dir.y = 0; // No vertical movement

                // Now move your character in world space
                body.LookAt(hit.point);

                // transform.Translate (dir * Time.DeltaTime * speed); // Try this if it doesn't work
            }
        }
        else if (lookMode == MouseLookMode.MOUSE_TO_AIM_2)
        {
            // this creates a horizontal plane passing through this object's center
            var plane = new Plane(Vector3.up, body.transform.position);
            // create a ray from the mousePosition
            var ray = mouseRay;
            // plane.Raycast returns the distance from the ray start to the hit point
            float distance;
            if (plane.Raycast(ray, out distance))
            {
                // some point of the plane was hit - get its coordinates
                Vector3 hitPoint = ray.GetPoint(distance);
                // use the hitPoint to aim your cannon

                // Now move your character in world space
                body.LookAt(hitPoint);
            }
        }
        else
        {
            body.Rotate(Input.GetAxis("Mouse X") * 30f);
        }
    }
Esempio n. 4
0
 private void OnEnable()
 {
     SetAny();
     verticalLookMode = (VerticalLookMode)Options.controllerLookMode;
     mouseLookMode    = (MouseLookMode)Options.mouseLookMode;
 }