course_heia_techimm_haptics.../Assets/Resources/Scripts/StepsLink/ArrowSript.cs

61 lines
1.3 KiB
C#
Raw Permalink Normal View History

2025-07-12 18:59:18 +02:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ArrowSript : MonoBehaviour
{
private GameObject targetObj;
// set the target obj
public void SetTargetObj(GameObject obj)
{
targetObj = obj;
}
// method to place the arrow over the passed object
private void PlaceArrowOverObject(GameObject obj)
{
// get the obj position
Vector3 objPos = obj.transform.position;
// put the arrow over the obj
transform.position = objPos;
// rotate the arrow to face the obj
transform.LookAt(obj.transform);
// increase the arrow height from the obj top
transform.position += new Vector3(0, 0.3f, 0);
// show
ShowArrow(obj);
}
// method to show the arrow
public void ShowArrow(GameObject obj)
{
// enable the arrow
gameObject.SetActive(true);
}
public void Update()
{
// rotate on y axis
transform.Rotate(0.5f, 0, 0);
// if the target obj is not null
if (targetObj != null)
{
// place the arrow over the target obj
PlaceArrowOverObject(targetObj);
}
}
// method to hide the arrow
public void HideArrow()
{
// disable the arrow
gameObject.SetActive(false);
}
}