当鼠标位于门(红色区域)时我想做点什么。我正在尝试投射射线,但射线没有击中门,而且我无法找到它到底击中的位置。另外我怎样才能发出Debug.DrawRay这条射线?
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, Mathf.Infinity))
{
if (hit.collider.tag == "InteractiveDoor")
{
doorInteractGameObject.SetActive(true);
}
else
{
doorInteractGameObject.SetActive(false);
}
}
Run Code Online (Sandbox Code Playgroud)
我创建了一个基本的第一人称控制器,但我的问题是当我向前和向侧面移动时,我移动得更快。
我如何在 1 个 Vector3 中添加moveDirectionForward和moveDirectionSide以便能够使用CharacterController.Move()而不是 CharacterController.SimpleMove()?
void MovePlayer() {
// Get Horizontal and Vertical Input
float horizontalInput = Input.GetAxis ("Horizontal");
float verticalInput = Input.GetAxis ("Vertical");
// Calculate the Direction to Move based on the tranform of the Player
Vector3 moveDirectionForward = transform.forward * verticalInput * walkSpeed * Time.deltaTime;
Vector3 moveDirectionSide = transform.right * horizontalInput * walkSpeed * Time.deltaTime;
// Apply Movement to Player
myCharacterController.SimpleMove (moveDirectionForward + moveDirectionSide);
Run Code Online (Sandbox Code Playgroud) 我有一个带有 1 个序列化字符串的测试脚本,我试图通过在 TextField 中输入一些内容来访问和修改它,但我不知道将 TextField 分配给什么。
测试脚本:
using UnityEngine;
public class Test : MonoBehaviour
{
[SerializeField] private string value;
}
Run Code Online (Sandbox Code Playgroud)
测试工具脚本:
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(Test))]
public class TestTool : Editor
{
[ExecuteInEditMode]
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
Rect textFieldRect = new Rect(EditorGUILayout.GetControlRect(false, EditorGUIUtility.currentViewWidth));
EditorGUI.DrawRect(textFieldRect, Color.gray);
EditorGUI.TextField(textFieldRect, "Type here...");
}
}
Run Code Online (Sandbox Code Playgroud)