forked from cgvr/DeltaVR
quest marker that floats up and down and turns towards player
This commit is contained in:
50
Assets/_PROJECT/Scripts/ModeGeneration/QuestMarker.cs
Normal file
50
Assets/_PROJECT/Scripts/ModeGeneration/QuestMarker.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
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
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user