118 lines
3.1 KiB
C#
118 lines
3.1 KiB
C#
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
public class ActionGestureInteraction : MonoBehaviour
|
||
|
{
|
||
|
public List<GameObject> objects;
|
||
|
|
||
|
private Transform rightHandTransform;
|
||
|
private GameObject player;
|
||
|
|
||
|
/**public int blinkUses;
|
||
|
public float blinkCooldown, blinkDistance, blinkSpeed, blinkDestinationMultiplier;
|
||
|
public LayerMask blinkLayerMask;**/
|
||
|
|
||
|
void Start()
|
||
|
{
|
||
|
|
||
|
player = GameObject.Find("XR Origin");
|
||
|
rightHandTransform = player.transform.Find("Camera Offset").Find("RightHand Controller").transform;
|
||
|
}
|
||
|
|
||
|
public void PerformAction(string action)
|
||
|
{
|
||
|
//Debug.Log(action);
|
||
|
//if (action == "Blink")
|
||
|
//{
|
||
|
//BlinkCast(); [DEPRECATED]
|
||
|
//}
|
||
|
//else
|
||
|
//{
|
||
|
foreach (var item in objects)
|
||
|
{
|
||
|
if (item.name == action)
|
||
|
{
|
||
|
Instantiate(item, rightHandTransform.position, Quaternion.identity);
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
//}
|
||
|
}
|
||
|
/**
|
||
|
int maxUses;
|
||
|
float cooldownTimer;
|
||
|
bool blinking = false;
|
||
|
Vector3 destination;
|
||
|
**/
|
||
|
private void Update()
|
||
|
{
|
||
|
// Blink cooldown action;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
/** [DEPRECATED]
|
||
|
void BlinkCast()
|
||
|
{
|
||
|
Transform cameraTransform = Camera.main.transform;
|
||
|
Transform playerTransform = player.transform;
|
||
|
ParticleSystem blinkTrail = player.transform.Find("BlinkTrail").GetComponent<ParticleSystem>();
|
||
|
maxUses = blinkUses;
|
||
|
cooldownTimer = blinkCooldown;
|
||
|
|
||
|
Blink();
|
||
|
if (blinkUses < maxUses)
|
||
|
{
|
||
|
if (cooldownTimer > 0)
|
||
|
{
|
||
|
cooldownTimer -= Time.deltaTime;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
blinkUses += 1;
|
||
|
cooldownTimer = blinkCooldown;
|
||
|
}
|
||
|
|
||
|
if (blinking)
|
||
|
{
|
||
|
|
||
|
var dist = Vector3.Distance(playerTransform.position, destination);
|
||
|
if (dist > 0.5f)
|
||
|
{
|
||
|
Debug.Log(Time.deltaTime * blinkSpeed);
|
||
|
playerTransform.position = Vector3.MoveTowards(playerTransform.position, destination, blinkDistance);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
blinking = false;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
void Blink()
|
||
|
{
|
||
|
if (blinkUses > 0)
|
||
|
{
|
||
|
blinkUses -= 1;
|
||
|
blinkTrail.Play();
|
||
|
//RaycastHit hit;
|
||
|
if (Physics.Raycast(playerTransform.position, playerTransform.forward, out hit, blinkDistance, blinkLayerMask))
|
||
|
{
|
||
|
Debug.Log(hit.transform.name);
|
||
|
destination = hit.point * blinkDestinationMultiplier;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
destination = (cameraTransform.position + cameraTransform.forward.normalized * blinkDistance) * blinkDestinationMultiplier;
|
||
|
//}
|
||
|
|
||
|
|
||
|
destination.y += Camera.main.transform.position.y;
|
||
|
blinking = true;
|
||
|
}
|
||
|
}
|
||
|
}**/
|
||
|
}
|