0
これはスクリプトでもあり、スポットライトにアタッチして、プレイヤーがウェイポイント間を移動しているときにスポットライトを回転させて点灯させます。特定の範囲のプレーヤーを検出すると、タレットが回転しないのはなぜですか?
しかし、私もタレットにスクリプトを添付すると、私は、砲台が180度のように回転して停止し、プレーヤーを追跡し続けることはありません。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RotateSpotlight : MonoBehaviour
{
public GameObject target;
public float smooth = 1f;
public float rangeSqr;
public float rotationSpeed;
Quaternion originalRotation;
private void Start()
{
originalRotation = transform.localRotation;
}
private void Update()
{
if (target.transform.position.x < transform.position.x + rangeSqr)
{
var targetRotation = Quaternion.LookRotation(target.transform.position - transform.position);
var str = Mathf.Min(rotationSpeed * Time.deltaTime, 1);
transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, str);
}
else
{
var str = Mathf.Min(rotationSpeed * Time.deltaTime, 1);
transform.rotation = Quaternion.Lerp(transform.rotation, originalRotation, str);
}
}
}
に見てみることができますか? – roelofs
@roelofsなぜタレットはプレーヤーに向かって回転し続けていないのですか?プレーヤーはウェイポイント間を移動していますが、タレットはそれを追跡していません。しかし、例えばスポットライトにスクリプトが添付されている場合、スポットライトは、プレーヤーが範囲内にいるときにプレーヤーを追跡し続けるでしょう。 –
タレットコードはどのように見えますか?私はこれがあまりにも情報が少ないと思う。 – roelofs