Files
2024-11-20 15:21:28 +01:00

40 lines
1.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace LuxLWRPEssentials.Demo {
public class MouseSelect : MonoBehaviour {
private Transform selectedTransform;
void Update() {
if (Input.GetMouseButtonDown(0)) {
RaycastHit hitInfo = new RaycastHit();
bool hit = Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitInfo);
if (hit) {
if (selectedTransform != null) {
var tg = selectedTransform.GetComponent<ToggleOutlineSelection>();
if(tg != null) {
tg.Select();
}
}
if (selectedTransform != hitInfo.transform) {
var tg = hitInfo.transform.GetComponent<ToggleOutlineSelection>();
if(tg != null) {
selectedTransform = hitInfo.transform;
tg.Select();
}
else {
selectedTransform = null;
}
}
else {
selectedTransform = null;
}
}
}
}
}
}