2022-03-12 22:26:35 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class ActionGestureInteraction : MonoBehaviour
|
|
|
|
{
|
|
|
|
public List<GameObject> objects;
|
2022-03-24 16:02:34 +00:00
|
|
|
public Camera playerCamera;
|
|
|
|
private Vector3 destination;
|
2022-03-12 22:26:35 +00:00
|
|
|
|
2022-03-24 16:02:34 +00:00
|
|
|
public Transform rightHandTransform;
|
2022-03-12 22:26:35 +00:00
|
|
|
private GameObject player;
|
2022-03-24 16:02:34 +00:00
|
|
|
public float projectileSpeed = 30;
|
2022-03-12 22:26:35 +00:00
|
|
|
|
2022-04-11 10:58:13 +00:00
|
|
|
private bool holdingWand;
|
|
|
|
|
2022-04-18 08:52:14 +00:00
|
|
|
public AudioSource noEssenceAudio;
|
|
|
|
|
2022-03-12 22:26:35 +00:00
|
|
|
void Start()
|
|
|
|
{
|
2022-03-24 16:02:34 +00:00
|
|
|
player = gameObject;
|
2022-03-12 22:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void PerformAction(string action)
|
|
|
|
{
|
2022-04-11 10:58:13 +00:00
|
|
|
Debug.LogWarning(action);
|
|
|
|
|
|
|
|
if (player.GetComponent<PlayerInfo>().GetRightHand() != null)
|
|
|
|
{
|
2022-04-25 08:46:51 +00:00
|
|
|
if (player.GetComponent<PlayerInfo>().GetRightHand().name.StartsWith("wand")) holdingWand = true;
|
2022-04-11 10:58:13 +00:00
|
|
|
}
|
2022-04-11 15:27:18 +00:00
|
|
|
else holdingWand = false;
|
2022-04-14 14:56:04 +00:00
|
|
|
|
2022-04-11 10:58:13 +00:00
|
|
|
|
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case "HorizontalLine":
|
|
|
|
if (holdingWand)
|
|
|
|
{
|
|
|
|
Debug.LogWarning("CAST BOLT");
|
|
|
|
ShootProjectile();
|
|
|
|
InstantiateIceBolt(objects[0]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Debug.LogWarning("WOODCUTTING ACTION");
|
|
|
|
}
|
2022-04-18 08:29:26 +00:00
|
|
|
break;
|
2022-04-11 10:58:13 +00:00
|
|
|
case "VerticalLine":
|
|
|
|
if (holdingWand)
|
|
|
|
{
|
|
|
|
Debug.LogWarning("WAND VERTICAL");
|
2022-04-18 08:52:14 +00:00
|
|
|
if (PlayerInfo.Instance.AddEssenceBasic(-1))
|
|
|
|
{
|
|
|
|
Vector3 spawnPoint = transform.position + playerCamera.transform.forward;
|
|
|
|
spawnPoint = new Vector3(spawnPoint.x, spawnPoint.y + 1, spawnPoint.z);
|
|
|
|
GameObject shield = Instantiate(objects[1], spawnPoint, Quaternion.Euler(-90, playerCamera.transform.eulerAngles.y - 180, 180));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
noEssenceAudio.Play();
|
|
|
|
}
|
2022-04-11 10:58:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Debug.LogWarning("VERTICAL");
|
2022-04-18 08:29:26 +00:00
|
|
|
|
2022-04-11 10:58:13 +00:00
|
|
|
}
|
2022-04-18 08:29:26 +00:00
|
|
|
break;
|
2022-04-11 10:58:13 +00:00
|
|
|
case "Circle":
|
|
|
|
if (holdingWand)
|
|
|
|
{
|
2022-04-11 15:27:18 +00:00
|
|
|
Debug.LogWarning("Arcing fireball");
|
|
|
|
|
2022-04-11 10:58:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-04-18 09:08:55 +00:00
|
|
|
GameObject minigame = FindMinigame();
|
|
|
|
if (minigame != null)
|
|
|
|
{
|
|
|
|
float distance = Vector3.Distance(transform.position, minigame.transform.position);
|
|
|
|
if(distance < 4f) minigame.GetComponent<WellController>().StartMinigame();
|
|
|
|
}
|
|
|
|
|
2022-04-11 10:58:13 +00:00
|
|
|
}
|
2022-04-18 08:29:26 +00:00
|
|
|
break;
|
2022-04-11 10:58:13 +00:00
|
|
|
case "Triangle":
|
|
|
|
if (holdingWand)
|
|
|
|
{
|
|
|
|
Debug.LogWarning("WAND TRIANGLE");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Debug.LogWarning("WOODCUTTING ACTION");
|
|
|
|
}
|
2022-04-18 08:29:26 +00:00
|
|
|
break;
|
2022-04-11 10:58:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*if (action == "Portal")
|
2022-03-24 16:02:34 +00:00
|
|
|
{
|
|
|
|
// Raycast to find portal were looking at.
|
|
|
|
var nearestPortal = FindPortalInFront();
|
|
|
|
Debug.Log(nearestPortal);
|
|
|
|
EnableDisablePortal(nearestPortal);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-12 22:26:35 +00:00
|
|
|
foreach (var item in objects)
|
|
|
|
{
|
2022-03-24 16:02:34 +00:00
|
|
|
if (item.name == action && action == "IceBolt")
|
2022-03-12 22:26:35 +00:00
|
|
|
{
|
2022-03-24 16:02:34 +00:00
|
|
|
ShootProjectile();
|
|
|
|
InstantiateIceBolt(item);
|
|
|
|
}
|
|
|
|
if (item.name == action && action == "IceWall")
|
|
|
|
{
|
|
|
|
// Make ice wall appear from below to block incoming projectiles
|
2022-03-12 22:26:35 +00:00
|
|
|
}
|
|
|
|
}
|
2022-04-11 10:58:13 +00:00
|
|
|
} */
|
2022-03-12 22:26:35 +00:00
|
|
|
}
|
2022-04-11 15:27:18 +00:00
|
|
|
void MinigameEnable(GameObject portal)
|
2022-03-12 22:26:35 +00:00
|
|
|
{
|
2022-03-24 16:02:34 +00:00
|
|
|
// Did the raycast catch a portal in front of us?
|
|
|
|
if (portal != null)
|
2022-03-12 22:26:35 +00:00
|
|
|
{
|
2022-03-24 16:02:34 +00:00
|
|
|
var distance = Vector3.Distance(portal.transform.position, this.transform.position);
|
|
|
|
Debug.Log(distance);
|
|
|
|
// Is the portal within a reasonable distance?
|
|
|
|
if (distance <= 10.0f)
|
2022-03-12 22:26:35 +00:00
|
|
|
{
|
2022-03-24 16:02:34 +00:00
|
|
|
var portalVFX = portal.transform.Find("PortalFX");
|
|
|
|
var portalTrigger = portal.transform.Find("Portal");
|
|
|
|
// if the nearest portal is already enabled, then disable, else enable.
|
|
|
|
if (portalVFX.gameObject.activeInHierarchy)
|
2022-03-12 22:26:35 +00:00
|
|
|
{
|
2022-03-24 16:02:34 +00:00
|
|
|
portalVFX.gameObject.SetActive(false);
|
|
|
|
portalTrigger.gameObject.GetComponent<PortalTeleporter>().enabled = false;
|
2022-03-12 22:26:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-24 16:02:34 +00:00
|
|
|
portalVFX.gameObject.SetActive(true);
|
|
|
|
portalTrigger.gameObject.GetComponent<PortalTeleporter>().enabled =true;
|
2022-03-12 22:26:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-03-24 16:02:34 +00:00
|
|
|
}
|
|
|
|
|
2022-04-11 15:27:18 +00:00
|
|
|
GameObject FindMinigame()
|
2022-03-24 16:02:34 +00:00
|
|
|
{
|
|
|
|
Ray ray = playerCamera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
|
|
|
|
RaycastHit hit;
|
|
|
|
LayerMask playerLayerMask = LayerMask.GetMask("Player");
|
|
|
|
if (Physics.Raycast(ray, out hit, playerLayerMask))
|
2022-03-12 22:26:35 +00:00
|
|
|
{
|
|
|
|
|
2022-03-24 16:02:34 +00:00
|
|
|
if (hit.transform.gameObject.transform.root.CompareTag("Portal"))
|
|
|
|
{
|
|
|
|
return hit.transform.gameObject.transform.root.gameObject;
|
2022-03-12 22:26:35 +00:00
|
|
|
}
|
|
|
|
}
|
2022-03-24 16:02:34 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShootProjectile()
|
|
|
|
{
|
|
|
|
Ray ray = playerCamera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
|
|
|
|
RaycastHit hit;
|
|
|
|
|
|
|
|
if (Physics.Raycast(ray, out hit))
|
|
|
|
{
|
|
|
|
destination = hit.point;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
destination = ray.GetPoint(1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void InstantiateIceBolt(GameObject item)
|
|
|
|
{
|
2022-04-11 10:58:13 +00:00
|
|
|
Debug.LogWarning("INSTANTIATE BOLT");
|
2022-04-07 14:03:21 +00:00
|
|
|
var projectileObj = Instantiate(item, rightHandTransform.position, playerCamera.transform.rotation) as GameObject;
|
2022-04-18 08:29:26 +00:00
|
|
|
projectileObj.GetComponent<Rigidbody>().velocity = (playerCamera.transform.forward).normalized * projectileSpeed;
|
2022-03-24 16:02:34 +00:00
|
|
|
}
|
2022-03-12 22:26:35 +00:00
|
|
|
}
|