[英]How do I make my platform move 90 degrees when they touch button unity
您好,我正在尝试让播放器与按钮碰撞时使平台旋转90度。 我没有线索atm,只能使我的平台反复旋转。 我希望它分开发生,因为每个平台都有其单独的按钮。 我正在使用团结和尖锐。 地图图片https://gyazo.com/0efce1c230d703b793cf7cab0384ee4e
橙色=按钮
我想移动通讯平台
将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);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.