Advertisement
Guest User

Mouse mapping

a guest
May 22nd, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class cursorController : MonoBehaviour {
  5.    
  6.     public GameObject cursor00;
  7.     public GameObject cursor11;
  8.     public GameObject mouse00;
  9.     public GameObject mouse11;
  10.     public GameObject mouseModel;
  11.    
  12.     Vector2 mapMouse(Vector3 screenZero, Vector3 screenOne, bool useZ){
  13.         Vector2 mouse = new Vector2(Input.mousePosition.x/Screen.width, Input.mousePosition.y/Screen.height);
  14.         float cursorX = Mathf.Lerp(screenOne.x, screenZero.x, mouse.x);
  15.         float cursorY;
  16.         if(useZ){
  17.             cursorY = Mathf.Lerp(screenZero.z, screenOne.z, mouse.y);
  18.         }
  19.         else{
  20.             cursorY = Mathf.Lerp(screenZero.y, screenOne.y, mouse.y);
  21.         }
  22.        
  23.        
  24.  
  25.         return new Vector2(cursorX,cursorY);   
  26.     }
  27.    
  28.  
  29.    
  30.     // Update is called once per frame
  31.     void Update () {
  32.         //Cursor
  33.         Vector2 cursor = mapMouse(cursor00.transform.position, cursor11.transform.position, false);
  34.         transform.position = new Vector3(cursor.x,cursor.y, transform.position.z);
  35.        
  36.         //mouse
  37.         Vector2 mousePos = mapMouse(mouse00.transform.position, mouse11.transform.position, true);
  38.         mouseModel.transform.position = new Vector3(mousePos.x, mouseModel.transform.position.y, mousePos.y);
  39.        
  40.        
  41.        
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement