[英]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.