This commit is contained in:
xinkl
2025-11-08 17:07:00 +08:00
parent ccf87a7a0f
commit 29f801ec12
18 changed files with 494 additions and 40 deletions

View 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;
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: b66dc4eb457cf8f499cb3a1aecea31da

View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "New MusicData", menuName = "MusicData")]
public class MusicData : ScriptableObject
{
public string musicName;
public List<MusicTick> musicTicks;
}
[System.Serializable]
public class MusicTick
{
public int tick;
public GameObject[] array = new GameObject[4];
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: c9dcf4ec3d0425d42b318ee7d3f378c7

View File

@@ -0,0 +1,40 @@
using UnityEngine;
using UnityEngine.InputSystem;
public class MusicGame : MonoBehaviour
{
public MusicData musicData;
bool isPlaying = false;
public Camera mainCamera;
public void Start()
{
mainCamera = Camera.main;
}
public void Update()
{
if (Keyboard.current.qKey.wasPressedThisFrame)
{
Play();
}
}
public void Play()
{
ActivateTick(musicData.musicTicks[0]);
}
private void ActivateTick(MusicTick tick)
{
// 实例化与这个tick关联的预制体Note
for (int i = 0; i < tick.array.Length; i++)
{
if (tick.array[i] != null)
{
Instantiate(tick.array[i], GetSpawnPosition(i), Quaternion.identity);
}
}
}
Vector3 GetSpawnPosition(int index)
{
return mainCamera.transform.position + new Vector3(-2 + index * 1.5f, 3, 8);
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 97ebb7f3ced387d4796dc276889e4026

View File

@@ -0,0 +1,23 @@
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerCtrl : MonoBehaviour
{
InputAction inputAction;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
inputAction = FindAnyObjectByType<PlayerInput>().actions["Move"];
inputAction.performed += (ctx) =>
{
Vector2 value = ctx.ReadValue<Vector2>();
Debug.Log(value);
};
}
// Update is called once per frame
void Update()
{
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 748c8a3f2bfe364418e75b14c8b279e4