Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我能';不要用脚本冻结我的相机,即使它显示';它冻结了所有轴_C#_Unity3d - Fatal编程技术网

C# 我能';不要用脚本冻结我的相机,即使它显示';它冻结了所有轴

C# 我能';不要用脚本冻结我的相机,即使它显示';它冻结了所有轴,c#,unity3d,C#,Unity3d,在过去的3个小时里,我一直在努力寻找答案,但我找不到任何对我有帮助的东西。它显示相机在进入立方体时已经有了约束,所以它可以工作,但是没有,因为它没有冻结相机。我已经不知道该怎么办了 using System.Collections; using System.Collections.Generic; using UnityEngine; public class LCOE : MonoBehaviour { public GameObject cam; Rigidbody

在过去的3个小时里,我一直在努力寻找答案,但我找不到任何对我有帮助的东西。它显示相机在进入立方体时已经有了约束,所以它可以工作,但是没有,因为它没有冻结相机。我已经不知道该怎么办了

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

public class LCOE : MonoBehaviour
{

    public GameObject cam;

    Rigidbody rig;

    private void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Player")
        {
            cam.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;

        }
    }
    private void OnTriggerExit(Collider other)
    {
        if (other.tag == "Player")
        {
            cam.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.None;

        }
    }
}
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
公共类LCOE:单一行为
{
公共游戏对象;
刚体钻机;
专用空对撞机(对撞机其他)
{
如果(other.tag==“玩家”)
{
cam.GetComponent().constraints=RigidbodyConstraints.FreezeAll;
}
}
私有无效OnTriggerExit(碰撞器其他)
{
如果(other.tag==“玩家”)
{
cam.GetComponent().constraints=RigidByConstraints.None;
}
}
}

更改刚体上的约束或IsKinetic只会禁用物理运动,但它仍将与父对象一起移动。您的相机不应是播放器的子对象,连接到相机的脚本应如下所示:

class MyCamera : MonoBehaviour{
    public Transform target;
    public Vector3 offset;
    public bool isMovementDisabled;

    void LateUpdate(){
        if(isMovementDisabled)
           return;
        transform.position = target.position + offset;
    }
}

或者使用cinemachine

这是一款混合/虚拟现实应用程序吗?这意味着摄像头是通过相应的SDK进行外部控制的?derHugo不,它只是一个连接到角色的摄像头。您是否尝试简单地将
ca.getcomponent.iskinetic=true