【问题标题】:Trying to transform position of gameobject unity using C#尝试使用 C# 转换游戏对象统一的位置
【发布时间】:2019-10-29 20:19:34
【问题描述】:

在尝试更改游戏对象的位置及其速度时,我需要一些帮助。我知道翻译游戏对象,但我不知道如何提高它的翻译速度。顺便说一句,我正在使用统一游戏引擎。

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

public class lightning : MonoBehaviour
{
    //This is lightning
    private GameObject name;

    // Start is called before the first frame update
    void Start()
    {
       name=GameObject.Find("car");
    }

    // Update is called once per frame
    void Update()
    {
     if (Input.Keydone("r")
       door.transform.Translate(-Vector3.right * Time.deltaTime);
    }
}

【问题讨论】:

  • 场景灯与设备的屏幕亮度完全不同。
  • 也就是说,你真的是指屏幕亮度还是场景中的灯光? - 你的代码和描述是相反的
  • 我会建议使用后处理堆栈来实现这样的事情。 Bloom和Auto Exposure的混合应该可以解决问题。您无法调高设备亮度。
  • @BrandonMiller 在 2019.2 测试版中,有一个适用于 iOS 和 android 设备的可写 Screen.brightness 字段:
  • 我正在使用游戏引擎。我正在尝试改变游戏引擎的亮度。

标签: c# unity3d light


【解决方案1】:

您可以使用的一种解决方法是在覆盖整个屏幕的 UI 层上使用黑色滤镜(最好是图像)。您可以相应地更改过滤器的不透明度,以实现“变暗”屏幕的感觉。

【讨论】:

  • 请在您的回答中提供一些示例代码,以说明应该如何提高您的回答质量和清晰度。
【解决方案2】:

听起来您的速度和加速度有问题。
我添加了一个速度变量和一个加速度变量,这两个变量可以使物体随着时间的推移越来越快。

由于这是物理学,我建议您在游戏对象上使用刚体 并操纵其速度或施加力(力 = 质量 * 加速度) 所以通过添加一个力,它会给物体一个加速度。

//This is lightning
private GameObject name;
private float speedFactor = 20;
private float accelearationFactor = 5;

// Start is called before the first frame update
void Start()
{
   name=GameObject.Find("car");
}

// Update is called once per frame
void Update()
{
 if (Input.Keydone("r") {
   door.transform.Translate(-Vector3.right * speedFactor * Time.deltaTime);
   speedFactor += accelearationFactor * Time.deltaTime;
 }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-24
    • 1970-01-01
    相关资源
    最近更新 更多