1
0
forked from cgvr/DeltaVR
Files
DeltaVR3DModelGeneration/Assets/_PROJECT/Scripts/ModeGeneration/QuestMarker.cs

57 lines
1.5 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class QuestMarker : MonoBehaviour
{
public Transform movingPart;
public float amplitude = 0.1f; // How far up/down it moves
public float frequency = 1.5f; // Speed of oscillation
public float heightAboveTarget = 1f;
private Vector3 startPos;
private Transform playerTransform;
// Start is called before the first frame update
void Start()
{
startPos = movingPart.localPosition;
}
// Update is called once per frame
void Update()
{
// Float up and down
float offset = Mathf.Sin(Time.time * frequency) * amplitude;
movingPart.localPosition = startPos + new Vector3(0f, offset, 0f);
if (playerTransform != null)
{
// Turn towards player
Vector3 lookTargetPos = new Vector3(playerTransform.position.x, transform.position.y, playerTransform.position.z);
transform.LookAt(lookTargetPos);
}
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player Head")
{
playerTransform = other.transform;
}
}
private void OnTriggerExit(Collider other)
{
if (other.gameObject.tag == "Player Head")
{
playerTransform = null;
}
}
public void MoveTo(Transform target)
{
transform.position = target.position + new Vector3(0, heightAboveTarget, 0);
}
}