46 lines
1.0 KiB
C#
46 lines
1.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using Unity.VisualScripting;
|
|
|
|
public class MouseController : MonoBehaviour
|
|
{
|
|
Vector3 lastFramePosition;
|
|
public Camera InterestingCamera;
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
if(InterestingCamera == null)
|
|
InterestingCamera = Camera.main;
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
HandleCamera();
|
|
HandleWorldInteraction();
|
|
}
|
|
|
|
void HandleCamera()
|
|
{
|
|
var currentFramePosition = InterestingCamera.ScreenToWorldPoint(Input.mousePosition);
|
|
|
|
if (Input.GetMouseButton(1))
|
|
{
|
|
var diff = lastFramePosition - currentFramePosition;
|
|
InterestingCamera.transform.Translate(diff);
|
|
}
|
|
|
|
lastFramePosition = InterestingCamera.ScreenToWorldPoint(Input.mousePosition);
|
|
}
|
|
|
|
void HandleWorldInteraction()
|
|
{
|
|
if (Input.GetMouseButtonDown(0))
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|