提问人:Thomas 提问时间:10/17/2023 更新时间:10/17/2023 访问量:29
unity c# 脚本中的拾音器物理问题
Trouble with pickup physics in unity c# script
问:
我是 unity 脚本的初学者,我在编写有关如何拾取对象的代码时遇到了麻烦。
我已经浏览了 4-5 个 YouTube 教程,但仍然无法拿起物体。当我尝试捡起物体时,物体根本没有移动。该对象具有网格碰撞器、网格渲染器和刚体。我用角色控制器、角色脚本和十字准线创建了一个角色。我根据 youtube 上的 brackeys 第一人称动作教程视频制作了这个角色。 移动脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public CharacterController controller;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = transform.right * x + transform.forward * z;
controller.Move(move);
}
}
mouselook 脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MouseLook : MonoBehaviour
{
public float mouseSensitivity = 1000f;
public Transform playerBody;
float xRotation = 0f;
// Start is called before the first frame update
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void Update()
{
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
playerBody.Rotate(Vector3.up * mouseX);
}
}
我想要一个剧本,可以让我的角色从场景中捡起一个物体。我希望它是什么样子的
答: 暂无答案
评论