unity 相机坏了并且无法控制地移动

问题描述 投票:0回答:0

我正在尝试让第一人称相机统一工作,我有 2 个对象。一个是相机。它有一个刚体和一个碰撞,另一个是一个留在相机前面的盒子。对于一些共鸣,如果我看是相机移开的某个方向。这些是脚本

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class move : MonoBehaviour
{
    public Rigidbody rb;
    public float speed=20;
    public float sens=360;
    // Start is called before the first frame update
    void Start()
    {
       
        Cursor.lockState = CursorLockMode.Locked;
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey("d"))
        {
            rb.AddRelativeForce( new Vector3(speed, 0, 0)-rb.velocity);
        }
        if (Input.GetKey("a"))
        {
            rb.AddRelativeForce( new Vector3(-speed, 0, 0)-rb.velocity);
        }
            if (Input.GetKey("w"))
        {
            rb.AddRelativeForce( new Vector3(0, 0, speed)-rb.velocity);
        }
        if (Input.GetKey("s"))
        {
            rb.AddRelativeForce( new Vector3(0, 0, -speed)-rb.velocity);
        }
         float speex = Input.GetAxisRaw("Mouse X") * Time.deltaTime;
         float speey = -Input.GetAxisRaw("Mouse Y") * Time.deltaTime;
        rb.transform.Rotate(sens*speey,sens*speex , 0);
         rb.transform.Rotate(0,0 , 0);
        rb.transform.localEulerAngles=new Vector3(rb.transform.localEulerAngles.x,rb.transform.localEulerAngles.y,0);
    }
}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class blockcreate : MonoBehaviour
{

    public GameObject cam;
    public GameObject cube;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
     cube.transform.position = cam.transform.forward+cam.transform.position; 
    }
}

我试过弄乱这两个代码,但我几乎没有想法,因为正方形似乎会影响相机,即使没有相应的代码

unityscript
© www.soinside.com 2019 - 2024. All rights reserved.