首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用代码更改CineMachine死区宽度?统一性

如何用代码更改CineMachine死区宽度?统一性
EN

Stack Overflow用户
提问于 2021-06-23 04:59:08
回答 1查看 695关注 0票数 1

所以我想知道如何用编码改变我的死区宽度或高度,我有一个碰撞探测器,所以当我的播放器与那个矩形碰撞时,我想把死区宽度更改为2,但我不知道如何做到这一点,我试图在网上搜索答案,但没有,所以我想在这里询问是否有人知道答案。

代码语言:javascript
复制
private void OnTriggerEnter2D(Collider2D other)
{
    if (other.gameObject.CompareTag("dead"))
    {
        Debug.Log("Dead Zone Width Changed");
    }
}

我代码的其余部分:

代码语言:javascript
复制
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;

public class stopcamera : MonoBehaviour
{
    public CinemachineVirtualCamera cam;
    
    // Start is called before the first frame update
    void Start()
    {
    }

    // Update is called once per frame
    void Update()
    {
    }

    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.CompareTag("dead"))
        {
            var composer = cam.GetCinemachineComponent<CinemachineComposer>();
            composer.m_DeadZoneWidth = 2f;
            Debug.Log("saman the third");
        }

    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-23 05:50:10

我想将死区宽度更改为2

若要更改Cinemachine虚拟相机的特定值,请执行以下操作。您首先需要获得ComponentBase of of (AimBodyNoise),这取决于您想要在哪个阶段更改值。你可以用GetCinemachineComponent(CinemachineCore.Stage.Body)做这件事。

然后更改所需的值,以确保将ComponentBase类型设置为与检查器中相同的值。在您的情况下,这将是CineMachineFramingTransposer

示例:

代码语言:javascript
复制
[SerializeField]
private CinemachineVirtualCamera virtualCam;

private CinemachineComponentBase componentBase;

private void Start() {
    // Get the componentBase of our virutalCam to adjust its values via code.
    componentBase = virtualCam.GetCinemachineComponent(CinemachineCore.Stage.Body);
}

private void OnTriggerEnter2D(Collider2D other) {
    if (!other.gameObject.CompareTag("dead")) {
        return;
    }

    // Check if the CinemachineCore.Stage.Body ComponentBase,
    // is set to the CinemachineFramingTransposer.
    if (componentBase is CinemachineFramingTransposer) {
        var framingTransposer = componentBase as CinemachineFramingTransposer;
        // Now we can change all its values easily.
        framingTransposer.m_DeadZoneWidth = 2f;
        Debug.Log("Dead Zone Width Changed");
    }
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68093734

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档