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;
|
||||
}
|
||||
}
|
||||
2
Assets/Gameplay/Scripts/Frist/CameraFollow.cs.meta
Normal file
2
Assets/Gameplay/Scripts/Frist/CameraFollow.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b66dc4eb457cf8f499cb3a1aecea31da
|
||||
17
Assets/Gameplay/Scripts/Frist/MusicData.cs
Normal file
17
Assets/Gameplay/Scripts/Frist/MusicData.cs
Normal 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];
|
||||
}
|
||||
2
Assets/Gameplay/Scripts/Frist/MusicData.cs.meta
Normal file
2
Assets/Gameplay/Scripts/Frist/MusicData.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c9dcf4ec3d0425d42b318ee7d3f378c7
|
||||
40
Assets/Gameplay/Scripts/Frist/MusicGame.cs
Normal file
40
Assets/Gameplay/Scripts/Frist/MusicGame.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
2
Assets/Gameplay/Scripts/Frist/MusicGame.cs.meta
Normal file
2
Assets/Gameplay/Scripts/Frist/MusicGame.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 97ebb7f3ced387d4796dc276889e4026
|
||||
23
Assets/Gameplay/Scripts/Frist/PlayerCtrl.cs
Normal file
23
Assets/Gameplay/Scripts/Frist/PlayerCtrl.cs
Normal 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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
2
Assets/Gameplay/Scripts/Frist/PlayerCtrl.cs.meta
Normal file
2
Assets/Gameplay/Scripts/Frist/PlayerCtrl.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 748c8a3f2bfe364418e75b14c8b279e4
|
||||
Reference in New Issue
Block a user