Mouse
How do I use Mouse
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: RPGCamera.cs
Copy
38 void UpdateDistance()
39 {
40 m_Distance = Mathf.Clamp( m_Distance - Input.GetAxis( "Mouse ScrollWheel" ) * ScrollModifier, MinimumDistance, MaximumDistance );
41 }
File name: RPGCamera.cs
Copy
58 void UpdateRotation()
59 {
60 if( Input.GetMouseButton( 0 ) == true || Input.GetMouseButton( 1 ) == true )
61 {
62 transform.Rotate( 0, Input.GetAxis( "Mouse X" ) * TurnModifier, 0 );
63 }
64
65 if( Input.GetMouseButton( 1 ) == true && Target != null )
66 {
67 Target.rotation = Quaternion.Euler( 0, transform.rotation.eulerAngles.y, 0 );
68 }
69 }
File name: ClickDetector.cs
Copy
7 void Update()
8 {
9 // if this player is not "it", the player can't tag anyone, so don't do anything on collision
10 if (PhotonNetwork.player.ID != GameLogic.playerWhoIsIt)
11 {
12 return;
13 }
14
15 if (Input.GetButton("Fire1"))
16 {
17 GameObject goPointedAt = RaycastObject(Input.mousePosition);
18
19 if (goPointedAt != null && goPointedAt != this.gameObject && goPointedAt.name.Equals("monsterprefab(Clone)", StringComparison.OrdinalIgnoreCase))
20 {
21 PhotonView rootView = goPointedAt.transform.root.GetComponent
22 GameLogic.TagPlayer(rootView.owner.ID);
23 }
24 }
25 }
File name: InputToEvent.cs
Copy
32 void Update()
33 {
34 if( DetectPointedAtGameObject )
35 {
36 goPointedAt = RaycastObject( Input.mousePosition );
37 }
38
39 if( Input.touchCount > 0 )
40 {
41 Touch touch = Input.GetTouch( 0 );
42 this.currentPos = touch.position;
43
44 if( touch.phase == TouchPhase.Began )
45 {
46 Press( touch.position );
47 }
48 else if( touch.phase == TouchPhase.Ended )
49 {
50 Release( touch.position );
51 }
52
53 return;
54 }
55
56 currentPos = Input.mousePosition;
57 if( Input.GetMouseButtonDown( 0 ) )
58 {
59 Press( Input.mousePosition );
60 }
61 if( Input.GetMouseButtonUp( 0 ) )
62 {
63 Release( Input.mousePosition );
64 }
65
66 if( Input.GetMouseButtonDown( 1 ) )
67 {
68 pressedPosition = Input.mousePosition;
69 lastGo = RaycastObject( pressedPosition );
70 if( lastGo != null )
71 {
72 lastGo.SendMessage( "OnPressRight", SendMessageOptions.DontRequireReceiver );
73 }
74 }
75 }
File name: PointedAtGameObjectInfo.cs
Copy
7 void OnGUI()
8 {
9 if (InputToEvent.goPointedAt != null)
10 {
11 PhotonView pv = InputToEvent.goPointedAt.GetPhotonView();
12 if (pv != null)
13 {
14 GUI.Label(new Rect(Input.mousePosition.x + 5, Screen.height - Input.mousePosition.y - 15, 300, 30), string.Format("ViewID {0} InstID {1} Lvl {2} {3}", pv.viewID, pv.instantiationId, pv.prefix, (pv.isSceneView) ? "scene" : (pv.isMine) ? "mine" : "owner: " + pv.ownerId));
15 }
16 }
17 }
File name: RotateCamera.cs
Copy
48 protected void Update() {
49 if (!rotate) return;
50 lookAngleY += inputManager.MouseAxis.x * horizAngleMove;
51 newRotY = Quaternion.Euler(0f,lookAngleY,0f);
52
53 lookAngleX += inputManager.MouseAxis.y * vertAngleMove;
54 lookAngleX = Mathf.Clamp(lookAngleX, -xAngleMin, xAngleMax);
55 newRotX = Quaternion.Euler(lookAngleX, pivotEulers.y, pivotEulers.z);
56
57 if (turnSmoothing > 0) {
58 pivotTransform.localRotation = Quaternion.Slerp(pivotTransform.localRotation, newRotX, turnSmoothing * Time.deltaTime);
59 transform.localRotation = Quaternion.Slerp(transform.localRotation, newRotY, turnSmoothing * Time.deltaTime);
60 } else {
61 transform.localRotation = newRotY;
62 pivotTransform.localRotation = newRotX;
63 }
64 }
File name: InputManager.cs
Copy
30 void Awake() {
31 _destroyOnLoad = destroyOnLoad;
32 mouseAxis = new Vector2(0,0);
33 }
File name: InputManager.cs
Copy
39 void Update() {
40 mouseAxis.x = Input.GetAxis("Mouse X");
41 mouseAxis.y = Input.GetAxis("Mouse Y");
42
43 if (InputEvent == null) return;
44
45 if (!GameManager.Instance.IsReady) return;
46
47 HighlightTile();
48
49 if (Input.GetMouseButtonUp(0)) {
50 if (GameManager.Instance.GameState.IsWaiting) {
51 UnHighlightTile();
52 InputEvent(InputActionType.GRAB_PIECE);
53 } else if (GameManager.Instance.GameState.IsHolding) {
54 InputEvent(InputActionType.PLACE_PIECE);
55 }
56 }
57
58 if (Input.GetMouseButtonUp(1)) {
59 if (GameManager.Instance.GameState.IsHolding) {
60 InputEvent(InputActionType.CANCEL_PIECE);
61 }
62 }
63
64 if (Input.GetAxis("Mouse ScrollWheel") > 0) {
65 InputEvent(InputActionType.ZOOM_IN);
66 }
67
68 if (Input.GetAxis("Mouse ScrollWheel") < 0) {
69 InputEvent(InputActionType.ZOOM_OUT);
70 }
71
72 if (Input.GetMouseButtonDown(2)) {
73 InputEvent(InputActionType.ROTATE);
74 } else if (Input.GetMouseButtonUp(2)) {
75 InputEvent(InputActionType.STOP_ROTATE);
76 }
77 }
File name: InputManager.cs
Copy
79 public void HighlightTile() {
80 if (GameManager.Instance.GameState.IsWaiting) {
81 UnHighlightTile();
82 currentNode = Finder.RayHitFromScreen
83 if (currentNode != null) {
84 Piece piece = currentNode.Piece;
85 if (piece != null) {
86 if (GameManager.Instance.CurrentPlayer.Has(piece)) {
87 currentNode.HighlightMove();
88 } else {
89 currentNode.HighlightEat();
90 }
91 }
92 }
93 }
94 }
Download file with original file name:Mouse
Mouse 16.696 lượt xem
Gõ tìm kiếm nhanh...