【问题标题】:How do I make my platform move 90 degrees when they touch button unity当他们触摸按钮统一时,我如何让我的平台移动 90 度
【发布时间】:2018-11-01 12:58:29
【问题描述】:

您好,当我的播放器与按钮发生碰撞时,我正在尝试让我的平台旋转 90 度。我对atm一无所知,只能让我的平台同步运行。我希望它单独发生,因为每个平台都有其单独的按钮。我正在使用统一和 csharp。 地图图片 https://gyazo.com/0efce1c230d703b793cf7cab0384ee4e

橙色 = 按钮

我想移动通讯平台

【问题讨论】:

  • 旋转我只想在触摸按钮时旋转 90 度的脚本gyazo.com/a1fc9ddc40c89c16e46e8c1c393a1151
  • 寻求调试帮助的问题(“为什么这段代码不起作用?”)必须包括所需的行为、特定的问题或错误以及重现它所需的最短代码在问题本身。没有明确的问题陈述的问题对其他读者没有用处。请参阅:How to create a Minimal, Complete, and Verifiable example
  • 速度 = 0?你要在编辑器中覆盖它吗?
  • 是的,但它不是正确的脚本,我只需要它来激活一个,所以我想我必须为每个平台制作单独的脚本

标签: c# unity3d animation rotation collision


【解决方案1】:

将 Collider2D 附加到 GameObject 使其成为 IsTrigger 并在代码上附加脚本

void OnTriggerEnter2D(Collider2D col)
{
    if(col.gameObject.tag=="Player")
       platformObject.transform.rotation.x=90; //could be Y too 
}

这样就可以了。

编辑

https://docs.unity3d.com/ScriptReference/Quaternion.Lerp.html

using UnityEngine;

public class Example : MonoBehaviour
{
    // Interpolates rotation between the rotations
    // of from and to.
    // (Choose from and to not to be the same as
    // the object you attach this script to)

    Transform from;
    Transform to;
    float speed = 0.1f;
    void Update()
    {
        transform.rotation = Quaternion.Lerp(from.rotation, to.rotation, Time.time * speed);
    }
}

【讨论】:

  • 从我在他的代码中看到的,他正试图让它不断旋转......
  • 我猜他只是想在用户与按钮碰撞时旋转。
  • 无论如何他都需要使用IsTrigger collider。
  • 但它会立即执行我希望它缓慢执行以便玩家可以爬上平台,
  • 哦,所以你需要使用四元数和 Lerp 函数。查看 Unity 文档
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-02-01
  • 1970-01-01
相关资源
最近更新 更多