简体   繁体   English

当他们触摸按钮时如何使平台移动90度

[英]How do I make my platform move 90 degrees when they touch button unity

Hello I am trying to make my platform rotate 90 degrees when my player collide with the button. 您好,我正在尝试让播放器与按钮碰撞时使平台旋转90度。 I have no clue atm and can only make my platform go around simentanously. 我没有线索atm,只能使我的平台反复旋转。 I want it to happen seperatly cause each platform has its seperate button. 我希望它分开发生,因为每个平台都有其单独的按钮。 I am using unity and csharp. 我正在使用团结和尖锐。 picture of map https://gyazo.com/0efce1c230d703b793cf7cab0384ee4e 地图图片https://gyazo.com/0efce1c230d703b793cf7cab0384ee4e

orange = button 橙色=按钮

i wanna move the correspondent platform 我想移动通讯平台

attach a Collider2D to GameObject make it IsTrigger and attach a script to it on code 将Collider2D附加到GameObject上,使其成为IsTrigger并将脚本附加到代码上

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

something like this would do. 这样的事情会做。

Edit 编辑

https://docs.unity3d.com/ScriptReference/Quaternion.Lerp.html 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);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM