commit428243f4a6Author: AsanoRema <asanorema2036@gmail.com> Date: Sat Aug 29 13:43:13 2026 +0300 Squashed commit of the following: commit68e78fa464Author: AsanoRema <asanorema2036@gmail.com> Date: Sat Aug 29 13:41:49 2026 +0300 Updated .gitignore commit9f87122a34Author: AsanoRema <asanorema2036@gmail.com> Date: Sat Aug 29 13:34:57 2026 +0300 Added Dohya commitf6a7547e84Author: AsanoRema <asanorema2036@gmail.com> Date: Fri Aug 21 17:59:13 2026 +0300 Fixed commitb98901c366Author: AsanoRema <asanorema2036@gmail.com> Date: Tue Aug 18 17:37:22 2026 +0300 Added new particle Package commitbb2f4a3b16Author: AsanoRema <asanorema2036@gmail.com> Date: Tue Aug 18 17:17:48 2026 +0300 Map mehanic ready to multiplayer commitc01ff800f6Author: AsanoRema <asanorema2036@gmail.com> Date: Tue Aug 18 16:16:19 2026 +0300 Squashed commit of the following: commit173bbb165cAuthor: henjkey <henjkey@gmail.com> Date: Fri Aug 14 18:51:23 2026 +0500 Mappp commitd559ab338aAuthor: henjkey <henjkey@gmail.com> Date: Thu Aug 13 18:42:41 2026 +0500 Map Controller Coordinates Target System Crosshair System Radar System
85 lines
2.5 KiB
C#
85 lines
2.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
|
|
public class ProximityActivate : MonoBehaviour
|
|
{
|
|
|
|
public Transform distanceActivator, lookAtActivator;
|
|
public float distance;
|
|
public Transform activator;
|
|
public bool activeState = false;
|
|
public CanvasGroup target;
|
|
public bool lookAtCamera = true;
|
|
public bool enableInfoPanel = false;
|
|
public GameObject infoIcon;
|
|
|
|
float alpha;
|
|
public CanvasGroup infoPanel;
|
|
Quaternion originRotation, targetRotation;
|
|
|
|
void Start()
|
|
{
|
|
originRotation = transform.rotation;
|
|
alpha = activeState ? 1 : -1;
|
|
if (activator == null) activator = Camera.main.transform;
|
|
infoIcon.SetActive(infoPanel != null);
|
|
}
|
|
|
|
bool IsTargetNear()
|
|
{
|
|
var distanceDelta = distanceActivator.position - activator.position;
|
|
if (distanceDelta.sqrMagnitude < distance * distance)
|
|
{
|
|
if (lookAtActivator != null)
|
|
{
|
|
var lookAtActivatorDelta = lookAtActivator.position - activator.position;
|
|
if (Vector3.Dot(activator.forward, lookAtActivatorDelta.normalized) > 0.95f)
|
|
return true;
|
|
}
|
|
var lookAtDelta = target.transform.position - activator.position;
|
|
if (Vector3.Dot(activator.forward, lookAtDelta.normalized) > 0.95f)
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (!activeState)
|
|
{
|
|
if (IsTargetNear())
|
|
{
|
|
alpha = 1;
|
|
activeState = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (!IsTargetNear())
|
|
{
|
|
alpha = -1;
|
|
activeState = false;
|
|
enableInfoPanel = false;
|
|
}
|
|
}
|
|
target.alpha = Mathf.Clamp01(target.alpha + alpha * Time.deltaTime);
|
|
if (infoPanel != null)
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.Space))
|
|
enableInfoPanel = !enableInfoPanel;
|
|
infoPanel.alpha = Mathf.Lerp(infoPanel.alpha, Mathf.Clamp01(enableInfoPanel ? alpha : 0), Time.deltaTime * 10);
|
|
}
|
|
if (lookAtCamera)
|
|
{
|
|
if (activeState)
|
|
targetRotation = Quaternion.LookRotation(activator.position - transform.position);
|
|
else
|
|
targetRotation = originRotation;
|
|
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime);
|
|
}
|
|
}
|
|
|
|
}
|