temp
This commit is contained in:
61
Assets/Gameplay/Scripts/Frist/CameraFollow.cs
Normal file
61
Assets/Gameplay/Scripts/Frist/CameraFollow.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class CameraFollow : MonoBehaviour
|
||||
{
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
private InputAction lookAction;
|
||||
private Vector2 lookInput;
|
||||
/// <summary>
|
||||
/// 跟随目标
|
||||
/// </summary>
|
||||
private Transform target;
|
||||
private Vector3 Lastposition;
|
||||
void Awake()
|
||||
{
|
||||
// 获取场景中的相机
|
||||
Camera camera = Camera.main;
|
||||
// 获取相机的 Transform
|
||||
Transform cameraTransform = camera.transform;
|
||||
// 获取相机的父级
|
||||
Transform parent = cameraTransform.parent;
|
||||
// 获取相机的父级下的所有子级
|
||||
Transform[] children = parent?.GetComponentsInChildren<Transform>();
|
||||
// 遍历所有子级
|
||||
}
|
||||
void Start()
|
||||
{
|
||||
target = GameObject.Find("Player").transform;
|
||||
Lastposition = target.position;
|
||||
PlayerInput playerInput = FindAnyObjectByType<PlayerInput>();
|
||||
lookAction = playerInput.actions.FindAction("Attack");
|
||||
lookAction.performed += (context) =>
|
||||
{
|
||||
var mousePos = Mouse.current.position.ReadValue();
|
||||
Ray ray = Camera.main.ScreenPointToRay(mousePos);
|
||||
Physics.Raycast(ray,out RaycastHit hit);
|
||||
|
||||
if (hit.collider != null)
|
||||
{
|
||||
GameObject obj = hit.collider.gameObject;
|
||||
Debug.Log($"点击到了物体: {obj.name}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("未点击到任何物体。");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
void FixedUpdate()
|
||||
{
|
||||
var offset = Lastposition - target.position;
|
||||
Lastposition = target.position;
|
||||
transform.position += offset;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user