Last active
June 8, 2022 08:59
-
-
Save Islington036/87b23cd9db9eac178b9439a02768f01c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class DirectionMark : MonoBehaviour | |
{ | |
//============================================================================= | |
// 変数 | |
//============================================================================= | |
// プレイヤーの情報 | |
[SerializeField, Tooltip("プレイヤーオブジェクト")] | |
private Transform player = null; | |
// カメラ情報 | |
[SerializeField, Tooltip("プレイヤーを映すカメラ")] | |
private Transform Camera = null; | |
// ターゲット | |
[SerializeField, Tooltip("追いかけるターゲット")] | |
private Transform Target = null; | |
//============================================================================= | |
// プロパティ | |
//============================================================================= | |
public Transform SetPlayer { get { return player; } set { player = value; } } | |
public Transform SetCamera { get { return Camera; } set { Camera = value; } } | |
public Transform SetTarget { get { return Target; } set { Target = value; } } | |
//============================================================================= | |
// アップデート | |
//============================================================================= | |
void Update() | |
{ | |
TurnAroundDirectionTarget(); | |
} | |
//============================================================================= | |
// 矢印を回転させる | |
//============================================================================= | |
private void TurnAroundDirectionTarget() | |
{ | |
// プレイヤーからターゲットまでのベクトルを計算 | |
Vector3 Direction = (Target.position - player.transform.position).normalized; | |
// 求めた方向への回転量を求める | |
Quaternion RotationalVolume = Quaternion.LookRotation(Direction, Vector3.up); | |
// カメラ情報を元に回転量の補正 | |
Quaternion CorrectionVolume = Quaternion.FromToRotation(Camera.transform.forward, Vector3.forward); | |
// 向きを反映 | |
transform.rotation = RotationalVolume * CorrectionVolume; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment