Fixed
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using TMPro;
|
||||
|
||||
|
||||
public class AdjustTimeScale : MonoBehaviour
|
||||
{
|
||||
TextMeshProUGUI textMesh;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
textMesh = GetComponent<TextMeshProUGUI>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetAxis("Mouse ScrollWheel") > 0f)
|
||||
{
|
||||
if (Time.timeScale < 1.0F)
|
||||
{
|
||||
Time.timeScale += 0.1f;
|
||||
}
|
||||
|
||||
Time.fixedDeltaTime = 0.02F * Time.timeScale;
|
||||
|
||||
if (textMesh != null)
|
||||
{
|
||||
textMesh.text = "Time Scale : " + System.Math.Round(Time.timeScale, 2);
|
||||
}
|
||||
|
||||
}
|
||||
else if (Input.GetAxis("Mouse ScrollWheel") < 0f)
|
||||
{
|
||||
if (Time.timeScale >= 0.2F)
|
||||
{
|
||||
Time.timeScale -= 0.1f;
|
||||
}
|
||||
|
||||
Time.fixedDeltaTime = 0.02F * Time.timeScale;
|
||||
|
||||
if (textMesh != null)
|
||||
{
|
||||
textMesh.text = "Time Scale : " + System.Math.Round(Time.timeScale, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnApplicationQuit()
|
||||
{
|
||||
Time.timeScale = 1.0F;
|
||||
Time.fixedDeltaTime = 0.02F;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 57a9bba4c7c6adc40805917ce487896a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 127325
|
||||
packageName: Particle Pack
|
||||
packageVersion: 3.1
|
||||
assetPath: Assets/UnityTechnologies/EffectExamples/Shared/Scripts/AdjustTimeScale.cs
|
||||
uploadId: 691001
|
||||
@@ -0,0 +1,84 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
public class ProximityActivate : MonoBehaviour
|
||||
{
|
||||
|
||||
public Transform distanceActivator, lookAtActivator;
|
||||
public float distance;
|
||||
public Transform activator;
|
||||
public bool activeState = false;
|
||||
public CanvasGroup target;
|
||||
public bool lookAtCamera = true;
|
||||
public bool enableInfoPanel = false;
|
||||
public GameObject infoIcon;
|
||||
|
||||
float alpha;
|
||||
public CanvasGroup infoPanel;
|
||||
Quaternion originRotation, targetRotation;
|
||||
|
||||
void Start()
|
||||
{
|
||||
originRotation = transform.rotation;
|
||||
alpha = activeState ? 1 : -1;
|
||||
if (activator == null) activator = Camera.main.transform;
|
||||
infoIcon.SetActive(infoPanel != null);
|
||||
}
|
||||
|
||||
bool IsTargetNear()
|
||||
{
|
||||
var distanceDelta = distanceActivator.position - activator.position;
|
||||
if (distanceDelta.sqrMagnitude < distance * distance)
|
||||
{
|
||||
if (lookAtActivator != null)
|
||||
{
|
||||
var lookAtActivatorDelta = lookAtActivator.position - activator.position;
|
||||
if (Vector3.Dot(activator.forward, lookAtActivatorDelta.normalized) > 0.95f)
|
||||
return true;
|
||||
}
|
||||
var lookAtDelta = target.transform.position - activator.position;
|
||||
if (Vector3.Dot(activator.forward, lookAtDelta.normalized) > 0.95f)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (!activeState)
|
||||
{
|
||||
if (IsTargetNear())
|
||||
{
|
||||
alpha = 1;
|
||||
activeState = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!IsTargetNear())
|
||||
{
|
||||
alpha = -1;
|
||||
activeState = false;
|
||||
enableInfoPanel = false;
|
||||
}
|
||||
}
|
||||
target.alpha = Mathf.Clamp01(target.alpha + alpha * Time.deltaTime);
|
||||
if (infoPanel != null)
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Space))
|
||||
enableInfoPanel = !enableInfoPanel;
|
||||
infoPanel.alpha = Mathf.Lerp(infoPanel.alpha, Mathf.Clamp01(enableInfoPanel ? alpha : 0), Time.deltaTime * 10);
|
||||
}
|
||||
if (lookAtCamera)
|
||||
{
|
||||
if (activeState)
|
||||
targetRotation = Quaternion.LookRotation(activator.position - transform.position);
|
||||
else
|
||||
targetRotation = originRotation;
|
||||
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9dda47b72d39443fcbaff0fcbb5f1bd4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 127325
|
||||
packageName: Particle Pack
|
||||
packageVersion: 3.1
|
||||
assetPath: Assets/UnityTechnologies/EffectExamples/Shared/Scripts/ProximityActivate.cs
|
||||
uploadId: 691001
|
||||
@@ -0,0 +1,160 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityTemplateProjects
|
||||
{
|
||||
public class SimpleCameraController : MonoBehaviour
|
||||
{
|
||||
class CameraState
|
||||
{
|
||||
public float yaw;
|
||||
public float pitch;
|
||||
public float roll;
|
||||
public float x;
|
||||
public float y;
|
||||
public float z;
|
||||
|
||||
public void SetFromTransform(Transform t)
|
||||
{
|
||||
pitch = t.eulerAngles.x;
|
||||
yaw = t.eulerAngles.y;
|
||||
roll = t.eulerAngles.z;
|
||||
x = t.position.x;
|
||||
y = t.position.y;
|
||||
z = t.position.z;
|
||||
}
|
||||
|
||||
public void Translate(Vector3 translation)
|
||||
{
|
||||
Vector3 rotatedTranslation = Quaternion.Euler(pitch, yaw, roll) * translation;
|
||||
|
||||
x += rotatedTranslation.x;
|
||||
y += rotatedTranslation.y;
|
||||
z += rotatedTranslation.z;
|
||||
}
|
||||
|
||||
public void LerpTowards(CameraState target, float positionLerpPct, float rotationLerpPct)
|
||||
{
|
||||
yaw = Mathf.Lerp(yaw, target.yaw, rotationLerpPct);
|
||||
pitch = Mathf.Lerp(pitch, target.pitch, rotationLerpPct);
|
||||
roll = Mathf.Lerp(roll, target.roll, rotationLerpPct);
|
||||
|
||||
x = Mathf.Lerp(x, target.x, positionLerpPct);
|
||||
y = Mathf.Lerp(y, target.y, positionLerpPct);
|
||||
z = Mathf.Lerp(z, target.z, positionLerpPct);
|
||||
}
|
||||
|
||||
public void UpdateTransform(Transform t)
|
||||
{
|
||||
t.eulerAngles = new Vector3(pitch, yaw, roll);
|
||||
t.position = new Vector3(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
CameraState m_TargetCameraState = new CameraState();
|
||||
CameraState m_InterpolatingCameraState = new CameraState();
|
||||
|
||||
[Header("Movement Settings")]
|
||||
[Tooltip("Exponential boost factor on translation, controllable by mouse wheel.")]
|
||||
public float boost = 3.5f;
|
||||
|
||||
[Tooltip("Time it takes to interpolate camera position 99% of the way to the target."), Range(0.001f, 1f)]
|
||||
public float positionLerpTime = 0.2f;
|
||||
|
||||
[Header("Rotation Settings")]
|
||||
[Tooltip("X = Change in mouse position.\nY = Multiplicative factor for camera rotation.")]
|
||||
public AnimationCurve mouseSensitivityCurve = new AnimationCurve(new Keyframe(0f, 0.5f, 0f, 5f), new Keyframe(1f, 2.5f, 0f, 0f));
|
||||
|
||||
[Tooltip("Time it takes to interpolate camera rotation 99% of the way to the target."), Range(0.001f, 1f)]
|
||||
public float rotationLerpTime = 0.01f;
|
||||
|
||||
[Tooltip("Whether or not to invert our Y axis for mouse input to rotation.")]
|
||||
public bool invertY = false;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
m_TargetCameraState.SetFromTransform(transform);
|
||||
m_InterpolatingCameraState.SetFromTransform(transform);
|
||||
}
|
||||
|
||||
Vector3 GetInputTranslationDirection()
|
||||
{
|
||||
Vector3 direction = new Vector3();
|
||||
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.GetKey(KeyCode.Q))
|
||||
{
|
||||
direction += Vector3.down;
|
||||
}
|
||||
if (Input.GetKey(KeyCode.E))
|
||||
{
|
||||
direction += Vector3.up;
|
||||
}
|
||||
return direction;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
// Hide and lock cursor when right mouse button pressed
|
||||
if (Input.GetMouseButtonDown(1))
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
}
|
||||
|
||||
// Unlock and show cursor when right mouse button released
|
||||
if (Input.GetMouseButtonUp(1))
|
||||
{
|
||||
Cursor.visible = true;
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
}
|
||||
|
||||
// Rotation
|
||||
if (Input.GetMouseButton(1))
|
||||
{
|
||||
var mouseMovement = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y") * (invertY ? 1 : -1));
|
||||
|
||||
var mouseSensitivityFactor = mouseSensitivityCurve.Evaluate(mouseMovement.magnitude);
|
||||
|
||||
m_TargetCameraState.yaw += mouseMovement.x * mouseSensitivityFactor;
|
||||
m_TargetCameraState.pitch += mouseMovement.y * mouseSensitivityFactor;
|
||||
}
|
||||
|
||||
// Translation
|
||||
var translation = GetInputTranslationDirection() * Time.deltaTime;
|
||||
|
||||
// Speed up movement when shift key held
|
||||
if (Input.GetKey(KeyCode.LeftShift))
|
||||
{
|
||||
translation *= 10.0f;
|
||||
}
|
||||
|
||||
// Modify movement by a boost factor (defined in Inspector and modified in play mode through the mouse scroll wheel)
|
||||
boost += Input.mouseScrollDelta.y * 0.2f;
|
||||
translation *= Mathf.Pow(2.0f, boost);
|
||||
|
||||
m_TargetCameraState.Translate(translation);
|
||||
|
||||
// Framerate-independent interpolation
|
||||
// Calculate the lerp amount, such that we get 99% of the way to our target in the specified time
|
||||
var positionLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / positionLerpTime) * Time.deltaTime);
|
||||
var rotationLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / rotationLerpTime) * Time.deltaTime);
|
||||
m_InterpolatingCameraState.LerpTowards(m_TargetCameraState, positionLerpPct, rotationLerpPct);
|
||||
|
||||
m_InterpolatingCameraState.UpdateTransform(transform);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 390f972b3a1e62341ad150cbe29782f3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 127325
|
||||
packageName: Particle Pack
|
||||
packageVersion: 3.1
|
||||
assetPath: Assets/UnityTechnologies/EffectExamples/Shared/Scripts/SimpleCameraController.cs
|
||||
uploadId: 691001
|
||||
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(CharacterController))]
|
||||
public class SimpleCharacterMotor : MonoBehaviour
|
||||
{
|
||||
public CursorLockMode cursorLockMode = CursorLockMode.Locked;
|
||||
public bool cursorVisible = false;
|
||||
[Header("Movement")]
|
||||
public float walkSpeed = 2;
|
||||
public float runSpeed = 4;
|
||||
public float gravity = 9.8f;
|
||||
[Space]
|
||||
[Header("Look")]
|
||||
public Transform cameraPivot;
|
||||
public float lookSpeed = 45;
|
||||
public bool invertY = true;
|
||||
[Space]
|
||||
[Header("Smoothing")]
|
||||
public float movementAcceleration = 1;
|
||||
|
||||
CharacterController controller;
|
||||
Vector3 movement, finalMovement;
|
||||
float speed;
|
||||
Quaternion targetRotation, targetPivotRotation;
|
||||
|
||||
|
||||
void Awake()
|
||||
{
|
||||
controller = GetComponent<CharacterController>();
|
||||
Cursor.lockState = cursorLockMode;
|
||||
Cursor.visible = cursorVisible;
|
||||
targetRotation = targetPivotRotation = Quaternion.identity;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
UpdateTranslation();
|
||||
UpdateLookRotation();
|
||||
}
|
||||
|
||||
void UpdateLookRotation()
|
||||
{
|
||||
var x = Input.GetAxis("Mouse Y");
|
||||
var y = Input.GetAxis("Mouse X");
|
||||
|
||||
x *= invertY ? -1 : 1;
|
||||
targetRotation = transform.localRotation * Quaternion.AngleAxis(y * lookSpeed * Time.deltaTime, Vector3.up);
|
||||
targetPivotRotation = cameraPivot.localRotation * Quaternion.AngleAxis(x * lookSpeed * Time.deltaTime, Vector3.right);
|
||||
|
||||
transform.localRotation = targetRotation;
|
||||
cameraPivot.localRotation = targetPivotRotation;
|
||||
}
|
||||
|
||||
void UpdateTranslation()
|
||||
{
|
||||
if (controller.isGrounded)
|
||||
{
|
||||
var x = Input.GetAxis("Horizontal");
|
||||
var z = Input.GetAxis("Vertical");
|
||||
var run = Input.GetKey(KeyCode.LeftShift);
|
||||
|
||||
var translation = new Vector3(x, 0, z);
|
||||
speed = run ? runSpeed : walkSpeed;
|
||||
movement = transform.TransformDirection(translation * speed);
|
||||
}
|
||||
else
|
||||
{
|
||||
movement.y -= gravity * Time.deltaTime;
|
||||
}
|
||||
finalMovement = Vector3.Lerp(finalMovement, movement, Time.deltaTime * movementAcceleration);
|
||||
controller.Move(finalMovement * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b388589949f9448aca1903107a88cb42
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 127325
|
||||
packageName: Particle Pack
|
||||
packageVersion: 3.1
|
||||
assetPath: Assets/UnityTechnologies/EffectExamples/Shared/Scripts/SimpleCharacterMotor.cs
|
||||
uploadId: 691001
|
||||
Reference in New Issue
Block a user