feat: scene built, basic function completed

This commit is contained in:
2026-07-03 22:06:54 +08:00
parent 1995835c12
commit 99bcfccc94
8 changed files with 221 additions and 191 deletions

View File

@@ -0,0 +1,18 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraControllerX : MonoBehaviour
{
[SerializeField]
private float mouseSpeed = 20f;
void Update()
{
float mouseX = Input.GetAxis("Mouse X");
transform.Rotate(Vector3.up * (mouseX * mouseSpeed));
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 54f70d5af29a406987058ba50db0a636
timeCreated: 1783053068

View File

@@ -0,0 +1,24 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraControllerY : MonoBehaviour
{
[SerializeField]
private float mouseSpeed = 500f;
private float pitch = 0f;
// Update is called once per frame
void Update()
{
float mouseY = Input.GetAxis("Mouse Y");
pitch -= mouseY * mouseSpeed * Time.deltaTime;
pitch = Mathf.Clamp(pitch, -90f, 30f);
transform.localRotation = Quaternion.Euler(pitch, 0f, 0f);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d5fcaeb18225e04419f9a3d6c48546a5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,52 +1,59 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Moving : MonoBehaviour
{
public float speed = 5f;
[SerializeField]
private Rigidbody rb;
[SerializeField]
private float jumpForce = 5f;
void Start()
{
}
// Update is called once per frame
void Update()
{
Vector3 direction = Vector3.zero;
if (Input.GetKey(KeyCode.W))
direction += Vector3.forward;
if (Input.GetKey(KeyCode.S))
direction += Vector3.back;
if (Input.GetKey(KeyCode.A))
direction += Vector3.left;
if (Input.GetKey(KeyCode.D))
direction += Vector3.right;
if (Input.GetKeyDown(KeyCode.Space))
rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
if (Input.GetKey(KeyCode.LeftControl))
Debug.Log("left ctrl active");
direction = direction.normalized;
transform.position += direction * (speed * Time.deltaTime);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Moving : MonoBehaviour
{
public float speed = 5f;
[SerializeField]
private Rigidbody rb;
[SerializeField]
private float jumpForce = 5f;
void Awake(){
rb = GetComponent<Rigidbody>();
}
void Start()
{
}
// Update is called once per frame
void Update()
{
Vector3 direction = Vector3.zero;
if (Input.GetKey(KeyCode.W))
direction += Vector3.forward;
if (Input.GetKey(KeyCode.S))
direction += Vector3.back;
if (Input.GetKey(KeyCode.A))
direction += Vector3.left;
if (Input.GetKey(KeyCode.D))
direction += Vector3.right;
if (Input.GetKeyDown(KeyCode.Space))
rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
if (Input.GetKey(KeyCode.LeftControl))
Debug.Log("left ctrl active");
direction = direction.normalized;
transform.position += direction * (speed * Time.deltaTime);
}
}