41 lines
1.1 KiB
C#
41 lines
1.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class pivot : MonoBehaviour
|
|
{
|
|
|
|
public float mouseSensitivity = 1.0f;
|
|
public Transform target;
|
|
private Vector3 lastPosition;
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
Vector3 targetP = target.position;
|
|
|
|
//transform.LookAt(target);
|
|
transform.LookAt(new Vector3(targetP.x, transform.position.y, targetP.z));
|
|
//transform.rotation = Quaternion.Euler(0, transform.rotation.y, 0);
|
|
|
|
if (Input.GetMouseButtonDown(1))
|
|
{
|
|
lastPosition = Input.mousePosition;
|
|
}
|
|
|
|
if (Input.GetMouseButton(1))
|
|
{
|
|
Vector3 delta = Input.mousePosition - lastPosition;
|
|
//transform.Translate(delta.x * mouseSensitivity, -delta.y * mouseSensitivity, 0);
|
|
transform.Translate(delta.x * mouseSensitivity, 0, delta.y * mouseSensitivity);
|
|
lastPosition = Input.mousePosition;
|
|
}
|
|
}
|
|
}
|