ui基本完毕,修了一大把的bug
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
[ExcludeFromCoverage]
|
||||
public class CameraController : MonoBehaviour
|
||||
{
|
||||
[Tooltip("Acceleration of the player")]
|
||||
public float acceleration = 100.0f;
|
||||
|
||||
[Tooltip("Maximum speed of the player while walking")]
|
||||
public float maxSpeed = 5.0f;
|
||||
|
||||
[Tooltip("Sensitivity of the mouse for pan / tilt.")]
|
||||
public float mouseSensitivity = 5.0f;
|
||||
|
||||
private float startTime = 0f;
|
||||
private float elapsedTime = 0f;
|
||||
|
||||
void Start()
|
||||
{
|
||||
startTime = Time.time;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
float dx = Input.GetAxis("Mouse X") * mouseSensitivity;
|
||||
float dy = Input.GetAxis("Mouse Y") * mouseSensitivity;
|
||||
|
||||
if (elapsedTime > 0.5f)
|
||||
{
|
||||
this.transform.parent.Rotate(Vector3.up, dx);
|
||||
|
||||
// Clamp pitch to [-80, 80] degrees
|
||||
var currentPitch = this.transform.eulerAngles.x;
|
||||
if (currentPitch > 180f) currentPitch -= 360f;
|
||||
var newPitch = Mathf.Clamp(currentPitch - dy, -80f, 80f);
|
||||
this.transform.localEulerAngles = new Vector3(newPitch, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
elapsedTime = Time.time - startTime;
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate()
|
||||
{
|
||||
// Check for player movement. We can handle input here because it is continuous and
|
||||
// not instantaneous like jumping.
|
||||
var rigidbody = this.transform.parent.GetComponent<Rigidbody>();
|
||||
if (Input.GetKey(KeyCode.W))
|
||||
{
|
||||
rigidbody.AddRelativeForce(Vector3.forward * acceleration, ForceMode.Acceleration);
|
||||
}
|
||||
if (Input.GetKey(KeyCode.A))
|
||||
{
|
||||
rigidbody.AddRelativeForce(Vector3.left * acceleration, ForceMode.Acceleration);
|
||||
}
|
||||
if (Input.GetKey(KeyCode.S))
|
||||
{
|
||||
rigidbody.AddRelativeForce(Vector3.back * acceleration, ForceMode.Acceleration);
|
||||
}
|
||||
if (Input.GetKey(KeyCode.D))
|
||||
{
|
||||
rigidbody.AddRelativeForce(Vector3.right * acceleration, ForceMode.Acceleration);
|
||||
}
|
||||
|
||||
// Clamp the player's velocity in the X and Z directions
|
||||
Vector2 xzVelocity = new Vector2(rigidbody.linearVelocity.x, rigidbody.linearVelocity.z);
|
||||
if (xzVelocity.magnitude > maxSpeed)
|
||||
{
|
||||
var xzClampedVelocity = maxSpeed * xzVelocity.normalized;
|
||||
rigidbody.linearVelocity = new Vector3(xzClampedVelocity.x, rigidbody.linearVelocity.y, xzClampedVelocity.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dca2007b8cabd9747a798832c390aaba
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,26 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
[ExcludeFromCoverage]
|
||||
public class Projectile : MonoBehaviour
|
||||
{
|
||||
public GameObject projectile;
|
||||
public float initialVelocity;
|
||||
public KeyCode FireKey;
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(FireKey))
|
||||
{
|
||||
// Remove other projectiles from the scene
|
||||
foreach(GameObject obj in GameObject.FindGameObjectsWithTag("Projectile"))
|
||||
{
|
||||
GameObject.Destroy(obj);
|
||||
}
|
||||
|
||||
var projectileInstance = GameObject.Instantiate(projectile, this.transform.position, Quaternion.identity);
|
||||
projectileInstance.GetComponent<Rigidbody>().linearVelocity = initialVelocity * this.transform.forward;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bad14770ea7af9e4baaa4dc184db69a3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,17 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class ToggleText : MonoBehaviour
|
||||
{
|
||||
public KeyCode toggleKey;
|
||||
|
||||
public GameObject textObject;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(toggleKey))
|
||||
{
|
||||
textObject.SetActive(!textObject.activeSelf);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0f4acb25588adc34a9d8453173077e89
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,13 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class UniqueMaterial : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
// Creates a unique instance of the material, decoupling it from the other objects.
|
||||
// This script is only used for the Slice demo to highlight slices and is not essential
|
||||
// for the fracturing/slicing code to work.
|
||||
this.GetComponent<MeshRenderer>().material = this.GetComponent<MeshRenderer>().material;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4fe57792e36ffc489b628556d1dc576
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user